This project implements a simple file transfer and command execution system using Python socket programming. It consists of two scripts: script1.py
and script2.py
.
The project enables users to upload a file from one script to another over a network connection. The receiving script saves the uploaded file, executes a command on it (such as determining the file type), and sends the command output back to the sender.
This system is useful for scenarios where files need to be transferred and processed remotely, such as automated file processing or remote administration tasks. It serves as a learning exercise for understanding network communication and file handling in Python.
File Upload:
- Establishes a connection to a server at a specified host and port.
- Sends the name and size of the file to be transferred.
- Sends the file content in chunks over the network using a socket connection.
File Reception and Command Execution:
- Listens for incoming connections on the specified port.
- Receives the name and size of the file to be transferred.
- Receives the file content in chunks over the network.
- Saves the received file to a designated directory.
- Executes a command on the received file (in this case, the
file
command to determine the file type). - Sends the command output back to the client.
- Clone the repository:
git clone https://github.com/Jaswanthravichandran/BugBase-Socket-Programming.git
- Navigate to the project directory:
cd BugBase-Socket-Programming
- Run the setup script:
python Setup.py
Note
You can install the Python requirements manually if you face any issues in setup.py
- Install python requirements:
pip install -r requirements.txt
Tip
Feeling lazy to set up, then try to run it on docker image.
-
Pull the Docker image:
docker pull jaswanthravichandran/socket:latest
-
Run the Docker Image:
docker run -p 9000:9000 image_name
-
Run the Script1.py:
- Now run the Script1.py from your localhost.
python Script1.py 'filename' localhost 9000
- Run the Script2.py first with the following command:
python Script2.py <port>
- Then run the Script1.py with the following command:
python Script1.py <'filepath'> <host> <port>