File Transfer Protocol:
FTP is an application protocol used to transfer files, and is based on TELNET protocol. It is a text based protocol, where the commands are sent in clear text.
FTP has two parts: ftp client and ftp server. FTP Server in general listens on standard port 21 and FTP client initiates the connection to the server.
There are two different tcp connections between Ftp Client and Ftp Server. The first connection established serves as the control channel, so is also be used to send out-of-band data (commands).
After initial login and password, client can choose the mode of data transfer, which can be any of EBCIDIC, ASCII or binary. By default it is ASCII, and is generally overidden by specifying 'bi'.
In binary/streaming mode, any number of files can be sent in a transaction, and client/server does not include End-Of-Record/End-Of-File characters at the end of the stream. So, it is harder to know when a transfer is complete.
In such cases, the party that reads data sends positive response when it reaches end of stream on read.
There are two different data transfer commands: RETR (get), STOR (put). Client sends HELP command to see whether the printed list from the server contains GZIP option. That serves as an indication that client can transfer compressed files.
By default, client sends a port number using PORT command to the server, letting the server know that it will start listening on that port.
On receiving PORT command, the server establishes data connection to the client on that port. That is, control connection is from client to the server and data connection is from server to the client. This default mode is also called Active mode.
The problem with Active mode of FTP is that when the client lies behind a firewall, server cannot connect back to the client. To overcome this situation, ftp also supports passive mode, where data connection is also initiated by client to the server.To let server know that it wants to use passive mode,
instead of using regular PORT command, ftp will send PASSIV command to the server. Then server will open a socket and sends the socket-id back to the client. Client will use servers ip and port to establish a TCP data connection to the server.
FTP works mostly fine in simple unsecured environment. Things get complicated in the environment of VPN tunnels (Encryption), Multi-homed network interfaces, NAT, firewalls and proxies.
It becomes harder to diagnose what went wrong in such situations, as there are many several ways things could go wrong. The following are some of the ways:
The problem with combination of VPN + Proxies/NAT is that proxy cannot intercept the fields in the packet as they are encrypted and hence cannot transform the IP address in the packet headers.
In case of multi-homed network interfaces, the problem arises when the party(server in Active mode, client in the passive mode) responsible for data transfer does not use its DNS resolved IP Address/interface for out going packets.
This situation is not very uncommon, as administrators configure it for load balancing purposes.
The problem with firewalls is that depending on the way firewalls are configured, routers can allow some ports and disallow certain port ranges, causing unpredictable behavior. This situation is harder to diagnose or prevent as there is no easy way
to know which ports are open and which are not for a particular host, with out help from the network administrator. Typically hackers use nmap or open ftp ports, but administrators work constantly to block such threats and thus it is harder without the help from the administrator to know which ports can be used.
Best solution in this scenario, is knowing which ports need to be opened and coordinating with network administrator to open those ports.
Even in a unsecured environment, the server or client could get into trouble as it could run out of disk space or waiting for the file locks etc... In such situations ftp will time out after waiting for the data transfer time out interval.
For large transfer or with dealyed transfers, tcp connection of the control channel could be terminiated by the intermediate routers.
Alternatives to FTP: SFTP & SCP. SFTP is similar to FTP but works on secure connection such as TLS sockets or ssh connections. It differs from SCP, as it provides options to query and manage remote and local directories.
wget and curl : They are good, but they cannot support put functionality.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment