Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.7 KB

File metadata and controls

51 lines (39 loc) · 1.7 KB

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