Skip to content

Nametho/python-tcp-file-transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python TCP File Transfer

This project is a simple, command-line based client-server application for transferring files using TCP sockets in Python.

The server listens for incoming connections. The client can connect and send a file. The server receives the file and saves it with a _copie suffix.


Skills Demonstrated

  • Socket Programming (Networking): Building both a TCP/IP client (SOCK_STREAM) and a server.
  • Client-Server Architecture: Understanding the relationship between a listening server (bind(), listen(), accept()) and a connecting client (connect()).
  • Simple Protocol Design: The client first sends the file name and size as metadata. This is a robust method that allows the server to know exactly how much data to expect.
  • Binary File I/O: Using rb (read binary) and wb (write binary) to handle all file types, not just text.
  • Error Handling: Basic FileNotFoundError exception handling on the client side.

How to Run

You will need two separate terminal windows to run this project.

Terminal 1 (Start the Server):

Run the server and specify a port to listen on (e.g., 8080).

python3 server.py 8080

The terminal will display:

En attente d'un fichier...

Terminal 2 (Start the Client):

Run the client, specifying the server's IP (e.g., localhost) and the same port.

python3 client.py localhost 8080

The client will ask you for a file :

Entrez le chemin du fichier à envoyer: my_document.pdf

When the file is sent, the server's terminal will display the details and confirm the saving :

Nouveau fichier reçu
---------------------
Titre:my_document.pdf
Taille:123456
Copie OK -> my_document.pdf_copie

About

A simple client-server file transfer application using TCP sockets in Python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages