diff --git a/Dockerfile.client b/Dockerfile.client new file mode 100644 index 0000000..d1860ec --- /dev/null +++ b/Dockerfile.client @@ -0,0 +1,17 @@ +# Use the official Python image +FROM python:3.11 + +# Expose the specified port +EXPOSE 12000 + +# Create and set the working directory +WORKDIR /app + +# Copy the local app files to the container +COPY ./src/myftp /app + +RUN dd if=/dev/urandom of=/app/file_local.txt bs=1024 count=10 +RUN dd if=/dev/urandom of=/app/image_local.png bs=1024 count=50 + +# Start your Python application +#CMD python client.py --debug 1 diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..5c0d5f0 --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,19 @@ +# Use the official Python image +FROM python:3.11 + +# Expose the specified port +EXPOSE 12000 + +# Create and set the working directory +WORKDIR /app + +# Copy the local app files to the container +COPY ./src/myftp /app + +# Create files with random content in the /server directory +RUN mkdir /server +RUN dd if=/dev/urandom of=/server/file1.txt bs=1024 count=10 +RUN dd if=/dev/urandom of=/server/image1.png bs=1024 count=50 + +# Start your Python application +#CMD python server.py --port_number 12000 --debug 1 diff --git a/README.md b/README.md index 1ca25e7..73e54c7 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,24 @@ You can run `python3 src/myftp/client.py` to start the client or `python3 src/my ### Server -By default, the server IP address or hostname or server name will be `127.0.0.1` (also known as `localhost`). The `--port_number` flag, if not specified will be by default `12000`. +By default, the server IP address or hostname or server name will be `0.0.0.0` (meaning it will bind to all interfaces). The `--port_number` flag, if not specified will be by default `12000`. -You can run `python3 src/myftp/server.py` to start the server or `python3 src/myftp/server.py --port_number --debug 1` for debugging purposes and to specify the port number. +You can run `python3 src/myftp/server.py` to start the server or `python3 src/myftp/server.py --ip_addr --port_number --debug 1` for debugging purposes and to specify the port number. + +## Testing with Docker + +### Dependencies + +`docker` and `docker-compose` + +### Setup + +- Make you are at the root of this repo. +- Build the system with `docker-compose up --build --remove-orphans`. +- Wait 10 seconds. +- 2 containers will be created on the same network `mynetwork`. Their respective IP addresses will be printed to stdout. +- Open two terminal windows: one for each of server and client. +- Run the server with `docker exec -it project-ftp_server_1 python server.py `. +- Run the client with `docker exec -it project-ftp_client_1 python client.py `. +- For the client, when asked to put in the ip address and port number of the server, you can put in `ftp_server 12000` or adjust to your chosen port number. The IP address is resolved by Docker so ftp_server can not be changed. +- Tear down everything with `docker-compose down`. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..fe2c48a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,35 @@ +version: "3" + +services: + ftp_server: + build: + context: . + dockerfile: Dockerfile.server + networks: + - mynetwork + command: + - sh + - -c + - > + sleep 10 && + echo "My IP: $(hostname -i)" && + tail -f /dev/null + image: ftp_server:latest + + ftp_client: + build: + context: . + dockerfile: Dockerfile.client + networks: + - mynetwork + command: + - sh + - -c + - > + sleep 10 && + echo "My IP: $(hostname -i)" && + tail -f /dev/null + image: ftp_client:latest + +networks: + mynetwork: diff --git a/src/myftp/client.py b/src/myftp/client.py index 93fc2a2..aaf4be1 100644 --- a/src/myftp/client.py +++ b/src/myftp/client.py @@ -38,6 +38,7 @@ class UDPClient: f"myftp> - {self.mode} - : Invalid command. Supported commands are put, get, summary, change and help" ) + # handling the "bye" command if command == "bye": client_socket.close() print(f"myftp> - {self.mode} - Session is terminated") diff --git a/src/myftp/server.py b/src/myftp/server.py index 8c639d7..13411a9 100644 --- a/src/myftp/server.py +++ b/src/myftp/server.py @@ -59,6 +59,14 @@ def init(): help="Port number for the server. Default = 12000", ) + parser.add_argument( + "--ip_addr", + default="0.0.0.0", + required=False, + type=str, + help="Port number for the server. Default = 12000", + ) + parser.add_argument( "--debug", type=int, @@ -76,7 +84,7 @@ def init(): # UDP client selected here if protocol_selection == "2": - udp_server = UDPServer("127.0.0.1", args.port_number, args.debug) + udp_server = UDPServer(args.ip_addr, args.port_number, args.debug) udp_server.run()