FTP Server
FTP Server
FTP, or File Transfer Protocol, is a standard network protocol used to transfer files between a client
and a server on a computer network. It is one of the oldest and most widely used protocols for file
transfer over a TCP-based network, such as the internet or an intranet.
1) File Transfer:
FTP enables the transfer of files from one host to another. It allows users to upload files from their
local machines to a remote server and download files from a remote server to their local
machines.
2) Client-Server Model:
FTP operates on a client-server model where one machine acts as the server, and others act as
clients. The server hosts the files and responds to requests from clients, which initiate file
transfers.
3) Connection Types:
FTP supports two types of connections:
Control Connection: Used for sending commands and receiving responses. It remains open during
the entire session.
Data Connection: Used for transferring actual data files. It is opened and closed for each file
transfer.
5) Authentication:
Users need to authenticate themselves with a valid username and password to access files on an
FTP server. This ensures secure access and prevents unauthorized file transfers.
6) Modes of Operation:
FTP operates in two modes:
Active Mode: The client opens a random port, and the server connects to it for data transfer.
Passive Mode: The server opens a random port, and the client connects to it for data transfer.
Passive mode is often used to overcome issues with firewalls and NAT.
7) Security Considerations:
While traditional FTP operates in plaintext, security extensions like FTPS (FTP Secure) and SFTP
(SSH File Transfer Protocol) provide encryption and secure authentication.
Authorizer
An "authorizer" is a component responsible for managing user authentication and
determining their permissions within an FTP server. The DummyAuthorizer class
in pyftpdlib is one implementation of an authorizer.
In [2]: class MyHandler(FTPHandler):
def on_connect(self):
# Called when a client connects
print(f"Connected to {self.remote_ip}")
def on_disconnect(self):
# Called when a client disconnects
print(f"Disconnected from {self.remote_ip}")
In [ ]: def run_ftp_server():
# Instantiate an authorizer
authorizer = DummyAuthorizer()
# Specify the address and port for the FTP server to listen on
address = ("10.10.100.175", 22)
if __name__ == "__main__":
run_ftp_server()
Enter username
abc
Enter password in numeric form
1234
Enter the path of your file
C:/Users/C3I ADMIN/Desktop/ftp_served
[I 2024-03-05 14:36:38] concurrency model: async
[I 2024-03-05 14:36:38] masquerade (NAT) address: None
[I 2024-03-05 14:36:38] passive ports: None
[I 2024-03-05 14:36:38] >>> starting FTP server on 10.10.100.175:22, pid=24464 <<<
[I 2024-03-05 14:37:04] 10.10.100.175:51430-[] FTP session opened (connect)
[I 2024-03-05 14:37:04] 10.10.100.175:51430-[] FTP session closed (disconnect).
Connected to 10.10.100.175
Disconnected from 10.10.100.175
[I 2024-03-05 14:37:07] 10.10.100.175:51432-[] FTP session opened (connect)
Connected to 10.10.100.175
[I 2024-03-05 14:37:08] 10.10.100.175:51432-[abc] USER 'abc' logged in.
[I 2024-03-05 14:37:08] 10.10.100.175:51432-[abc] CWD C:\Users\C3I ADMIN\Desktop\ftp_served 250
User abc logged in
[I 2024-03-05 14:42:08] 10.10.100.175:51432-[abc] Control connection timed out.
[I 2024-03-05 14:42:08] 10.10.100.175:51432-[abc] FTP session closed (disconnect).
Disconnected from 10.10.100.175
Now download any FTP manager which can host this FTP server
(for this we can use cyberduck for its user friendly interface)
The above code is for the same system but what if we have to see
the file content on other device for example in your phone ?
For that download "AndFTP" for Android or "FTPManager" for iOS.
Now connect your PC with your Mobile Hotspot.
Note that you have to put the wifi IP address in your code in "Address" field or otherwise it will not work.
Now open the app and add new connection and enter the details.
The contents of the server will now be displayed on your phone.