A simple implementation of the rfc file transfer protocol. This is just for homework.
- Server should be running on linux system.
- Client require python3 and PyQt5 to work.
pip install -r client/requirements.txt
Should work just fine.
First compile the source code. You can do this simply by running make. A binary
file will be created at ./server/server
.
Run the server with following command.
server/server [-port N] [-root DIR]
Server would be running on port N with working directory at DIR.
Move into client directory.
python3 main.py
The main process of server runs on a infinite loop waiting for connection from any client. If a connection is accepted, the main process create a subprocess for handling commands sent from the client. So the server supports talking to multiple clients.
Subprocesses also run on a loop receiving instructions from the client, gettings the job done and sending messages back to the client.
The subprocess receives commands from clients and parses them into a struct
called CommandList
. After parsing the command, the subprocess goes to
ftp_{cmd}
to get the job done.
States for the server/client are stored in struct server_ctx
, and passed to every
ftp function as a argument. So ftp functions
can know whether the client has already logged in or the client has sent a
PASV
before a data transfer command.
The FtpClient
class is a wrapper around socket
. It provides useful ftp
functions such as login
, throw errors on every bad response from server,
works pretty much like ftplib
from python standard library.
Uploading and Downloading file would be running in another thread, so the ui will not be freezed.
- user
- pass
- port
- pasv
- retr
- stor
- quit
- syst
- type
- mkd
- cwd
- cdup
- pwd
- list (partial support, does not accept any argument)
- rmd
- dele
- rnfr
- rnto
- abor (cannot interrupt data transfer, this is actually same as quit)
- rest
Note that server could only perform data transfer in binary mode.
The client works out of the box. You don’t need to know about ftp commands to use it.
Note that it does not support user custom commands.