File sharing protocol is implemented between a client and a server using File Transfer Protocol (FTP) which uses TCP/IP protocol to communicate between ports.
Python 3 is used for implementing this client server architecture. Libraries used are:
- socket
- os, sys
- hashlib
- tqdm
- struct
- time
- subprocess
- shutil
There are two files, client.py and server.py. Both the files can be put in same folder in your local machine or different folders. Open two different terminals and in the respective folder run:
python3 client.pypython3 server.pyIn the client side, Enter your name prompt will come and upon entering a virtual terminal will be created. If the connection with the server is successful Server bind complete will be printed on the server side.
lsDisplays the files in the folder in which server.py is run.
lcDisplays the files in the folder in which client.py is run.
quitQuits the connection with the server
historyDisplays the commands used in the current session.
IndexGet longlistDisplays the entire list of files in folder of the server with filesize, timestamp, name and filetype.
IndexGet longlist *.txt wordDisplays the entire list of *.txt files with a particular word in it in folder of the server with filesize, timestamp, name and filetype.
IndexGet shortlist <YYYY-MM-DD_HH:MM:SS> <YYYY-MM-DD_HH:MM:SS>Displays the entire list of files in folder of the server with filesize, timestamp, name and filetype between a specific set of timestamps.
IndexGet shortlist <YYYY-MM-DD_HH:MM:SS> <YYYY-MM-DD_HH:MM:SS> *.filetypeDisplays the list of files of type *.txt or *.pdf in folder of the server with filesize, timestamp, name and filetype between a specific set of timestamps.
FileHash checkallDisplays the filename, MD5 Checksum of the file on both the server and client side and last modified timestamp of all the files in the server side. It checks the hash of the files on both the client and server side and prints whether they match or not.
FileHash verify filenameDisplays the filename, MD5 Checksum of the file on both the server and client side and last modified timestamp of the file in the server side. It checks the hash of the file on both the client and server side and prints whether they match or not.
FileUpload filename modeUploads file with either TCP or UDP protocols.
FileDownload filename modeDownloads file from the server using TCP or UDP and displays filename, filesize, MD5checksum and timestamp.
Cache verify filenameThe size of the cache is 3 and the cache is session specific. This commands checks the presence of file in the session cache and if it is there it prints the Filename and Filesize and if it is not it calls the FileDownload command with TCP and downloads it in the Cachefolder. If the cache is full then the file with least number of requests in the current session is removed form Cachefolder.
Cache showThe size of the cache is 3 and the cache is session specific. This commands displays the Filename and Filesize of all the files in the Cachefolder.