To build a simple file transfer system using Python’s socket library — allowing a client to send files directly to a server. This project aims to improve understanding of network programming, data streaming, and basic file handling.
- Consists of both client and server applications.
- Allows clients to select and send any local file to a server over TCP.
- The server receives and saves the file to a chosen destination folder.
- Built with simplicity and reusability in mind.
- Language: Python
- Frameworks/Libraries: socket, os, sys
- Tools: Git, GitHub, VS Code
Extracting the filename to be sent over the connection as well as the data. This lead me to finding about the basename function in the os module to extract the filename which i then build into the program by making it send the file name first to the server program and then sending out the rest of the file. Another challenge for me was understanding the sockets module better as i took some time away due to college commitments
Successfully created a functioning file transfer system that demonstrates the fundamentals of Python’s networking module. Built confidence in working with sockets and handling binary data streams.
- Implement secure transfer using SSL.
- Try to improve understanding of sockets.
Ensure both server.py and client.py are in the same directory.
-
Open a terminal and navigate to the project directory.
-
Run:
python server.py
-
You’ll be prompted to enter the destination folder where received files should be saved.
-
The server will then start listening for incoming connections.
-
Open another terminal window in the same directory.
-
Run:
python client.py
-
You’ll be prompted to input a file path for the file you wish to send.
-
The client connects to the server, transfers the file name first, waits for acknowledgment, and then streams the file data.
- The server receives the filename, acknowledges it, and starts saving the incoming data.
- Once the file transfer completes, the server confirms successful reception.
- The client prints a message confirming that the file was sent successfully.
- To stop the client, simply close the terminal after the confirmation message.
- To stop the server, press
Ctrl + Cin the terminal.
Client Output
Please input a file path: example.txt
File sent successfully.
Server Output
Server is listening on 127.0.0.1:12345
Connection established with ('127.0.0.1', 57344)
Input folder path where data is to go: C:\Downloads
Receiving file: example.txt
File successfully received and saved to C:\Downloads\example.txt
This project is licensed under the MIT License.