A client-server Implementation of the File Transfer Protocol closely following RFC-959 and Beej's Guide.
The developer was too lazy to make a screencast. You may want checkout the logs.
- Closely follows the official spec for FTP :
RFC-959 - Provides basic authentication with multiuser support.
- Supports multiple client connections.
- Handles control connection (
PI) and data connection (DTP) separately. - Supports switching of data connection port with
PORTcommand. - Works over
localhost,local networkand over theinternet.
Click here to know about all the supported commands.
All command mentioned below are case insensitive unless otherwise specified.
| Command | Usage | Action |
|---|---|---|
| HELP | help |
Show all the available commands |
!<cmd> |
!pwd!cd ..!mkdir clientDir |
Execute a command on the client itself. Because they are directly executed on client system, these are case sensitive. |
| NOOP | noop |
Execute No operation. Serves as a dummy command. |
| USER | USER <username>user root |
Provide username for login |
| PASS | PASS <password>pass root |
Provide password for login |
| SYS | sys |
Get System Details Of server |
| PWD | pwd |
Print working directory |
| LIST | LISTlsls serverDir |
List directory contents |
| CWD | cwd ..cd ..cd serverDir |
Change working directory |
| CDUP | cdup |
Change to parent directory |
| MKD | mkd dirNamemkdir dirName |
Make directory |
| RMD | rmd dirNamermdir dirName |
Remove directory |
| STOR | STOR putFileOnServer.txtput putFileOnServer.txt |
Send File to Server |
| RETR | RETR getFileFromServer.txtget getFileFromServer.txt |
Retrive File from Server |
| PORT | PORT <IP> <Port> PORT CURRENT_MACHINE_IP 5643 PORT localhost 9584 PORT 200.212.111.32 8868 |
Switch data connection IP, Port |
| QUIT | quitexit |
Quit the application |
| ABORT | abortabor |
Abort the last command and related data transfer |
| PASV | pasv |
Switch to Passive Receive Mode |
| TYPE | TYPE A E |
Switch the representation type. Default is ASCII Non Print. |
| MODE | MODE S |
Switch the transfer mode. Default is Stream. |
| STRU | STRU F |
Switch the File structure Type. Default is File. |
git cloneandcdin the folder- make sure you have
makeinstalled, then runmake -s - it will create a bin folder with two executables
clientandserver
- go to where executables live
cd ./bin serverneeds to be started first. Usage is as follows../serverThis usesport=9000as default../server <portNumber>in case you want to supply custom port number.
clientcan be started as follows../clientThis useshost=localhostandport=9000as defaults../client <serverIP> <serverPort>in case server is on different machine.
The code has been tested in all three cases mentioned above.
The maximum file size tested is 190 MB over the internet and 2.5 GB over localhost.
In theory, it should work for even bigger file sizes.
File integrity is intact, no corruption occurs during the transfer.
Click here to know more about the testing details.
- Both client and server are on same machine.
- Use
127.0.0.1orlocalhostas Server IP
- Both system are on Local Network
- use localIPs like
192.168.0.9. You must know server's local IP for this.
- Both systems want to transfer files over the internet.
- Internet Testing has been done with VM instances for below 2 scenarios.
Scenario 1: Server and client are both on different VMs. Both have static IP.scenario 2: Server is on VM with static IP. Client is my machine (behind a router).- VM-1 on Google cloud
ssh jatin@ftp-tester-1: acts as server - VM-2 on Google cloud
ssh jatin@ftp-tester-2: acts as client
- Ensure that server has
static IP. The easiest way to know if a machine has astatic internet IPis :- Run the server program on the machine you wish to test for static IP
- From any other machine
telnet <machineInternetIP> <portOnWhichServerIsRUnning=9000> - To obtain a machine's internet IP, use
curl ifconfig.me - It should ideally establish connection, because FTP is based on the telnet protocol. If however, it says
No route to Host, then it means the machine is behind a router and NAT is your enemy.
- Things to keep in mind while creating your VMs for testing -
- First, create some
VM instanceson google cloud. Make sure you have free credits. - Server needs to have a static IP. In your project, go to
VPC network>External IP addressesand reserve static IP address for your machines. - On google cloud, all ports are blocked by default. But our ftp-server should be allowed to use ports freely. So we have to add two
Firewall rulesto allowingress and egress trafficonall portsonall protocolsaccessible byall IPsi.e.0.0.0.0/0 - Setup ssh login. Then login using
ssh <username>@<external-IP> - If you don't want to remember external IP's you can also add custom hostnames and resolve them in your
/etc/hostsfile - Then
clonethe project,makeit, and run - To connect to server, client needs to know server's
static internet ip. That's a pre-requisite.
- First, create some
How to analyse what's happening behind the scenes ?
- Monitoring system calls with
stracestracewill allow you to monitor relevant system calls as they happen.- go to where executable live
cd ./bin strace -fe trace=process,network,signal ./bin/server 9000strace -fe trace=process,network,signal ./bin/client 127.0.0.1 9000
- Monitoring processes, their children, pid, ppid, pgid with
ps- Use
ps fjto see the tree format of all the forks, along with their pid's and ppid's.
- Use
- Generating logs with
tee. This is very unpredictable for interactive programs.make | tee logs/makelog.txt./bin/server | tee logs/serverlog.txt./bin/client | tee logs/clientlog.txt
- Hiding all the server logs with output redirection
- To hide all output from server, send it to the null device
./server &>/dev/null
How is the code in the project formatted ?
- a
chromiumbased,opinionated.clang-formatfile is present in project root. - This has been used for all the formatting in this project.
- Set your IDE format settings to file.
- For VS Code, add these in your
setting.json"C_Cpp.clang_format_path": "/usr/bin/clang-format-3.8", "C_Cpp.clang_format_style": "file", "C_Cpp.clang_format_fallbackStyle": "Chromium",
- Build your own formatter file here
- Know more about unified formatting across IDE's here
How much work was involved in the project? What's the future scope?
- The project was divided into a lot of small tasks.
- The tasks belonged either of the three categories -
- Must have features,
- Good to have features, and
- Future scope.
- You can find all these details in the extended todo list