Question: Implement a simplified FTP server that works with the Windows built-in FTP client. You must make your own TCP socket, and cannot use any existing

Implement a simplified FTP server that works with the Windows built-in FTP client. You must make your own TCP socket, and cannot use any existing FTP library. You may use Python3, Java, C++, or C as the programming language. The FTP server should be started by typing the command:


myftpserveror

java myftpserveror

python myftpserver.py


So that the server will be running at the local IP address and listening at the TCP port 21. The current directory where the server program is started will be the FTP root directory.


After the server starts, it should provide the following services for a user connecting via the Windows built-in FTP client [3], which can be started by typing"ftp"in the Windows command line terminal.


Client command Server service
login Allow the client to login if the provided user id is "guest" and password is "guest".
cd remote-path Change the working directory of the client on the server to "remote-path".
pwd Return the working directory of the client.
get remote-file Send the file named "remote-file" from the server to the client.
put local-file Receive the file named "local-file" from the client to the server, and save it in the working directory with the same file name.
delete remote-file Delete the file named "remote-file" from the working directory.
quit Disconnect the FTP client.


If the server encounters an error when executing the client command, it should send an error notification to the client. Refer to the RFC [1] for appropriate response messages. For example, when the client provides the wrong user name or password, the servershould return "530 Login incorrect."; when the client requests to create adirectory that already exists, the server should return "550Createdirectory operation failed.".


Below I have provided skeleton code


from socket import socket, AF_INET, SOCK_STREAM  # create listening socket  listening_socket = socket(AF_INET, SOCK_STREAM)  # bind listening socket to all IP addresses and port 21  listening_socket.bind(('0.0.0.0', 21))  # start listening  listening_socket.listen()  print('Server listening at port 21')  # loop forever  while True:      # create control socket for new request      control_socket, addr = listening_socket.accept()      print(f'Client from {addr} connected')      # send welcome message      control_socket.send(bytes('220 Welcome to myftpserver!\r\n', 'utf-8'))      loop = True      username = None      password = None      authenticated = False      current_directory = '/'      while loop:          # read client command from socket          command = control_socket.recv(1024).decode('utf-8').strip()          print(f'Client command: {command}')                    # for OPTS command          if command.startswith('OPTS UTF8'):              control_socket.send(bytes('200 OK.\r\n', 'utf-8'))          # for USER command          elif command.startswith('USER '):              command = command.replace('USER ', '')              username = command              control_socket.send(bytes('331 Please specify the password.\r\n', 'utf-  8'))          # for PASS command          elif command.startswith('PASS '):              command = command.replace('PASS ', '')              password = command              if username == 'guest' and password == 'guest':                  control_socket.send(bytes('230 Login successful.\r\n', 'utf-8'))                  # successful login                  print(f'Client status: user authenticated')                  authenticated = True              else:                  username = None                  password = None                  control_socket.send(bytes('530 Login incorrect.\r\n', 'utf-8'))                  control_socket.close()                  print('Client disconnected')                  loop = False          # for PWD command          elif command.startswith('XPWD'):              if authenticated:                  control_socket.send(bytes(f'257 "{current_directory}" is the   current directory.\r\n', 'utf-8'))              else:                  control_socket.send(bytes('530 Login incorrect.\r\n', 'utf-8'))                  control_socket.close()                  print('Client disconnected')                  loop = False          # for QUIT command          elif command == 'QUIT':              control_socket.send(bytes('221 Goodbye.\r\n', 'utf-8'))              control_socket.close()              loop = False              print(f'Client status: user disconnected')          # command not implemented yet          else:              control_socket.send(bytes('Command not supported.\r\n', 'utf-8')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is a simplified FTP server implementation in Python using the provided skeleton code python from socket import socket AFINET SOCKSTREAM import os create listening socket listeningsocket socketAFI... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!