Table of Contents


Concepts

File Transfer Protocol (FTP) is a network protocol used to transfer files between clients and servers, allowing uploads, downloads, and remote file management. Created in 1971 by Abhay Bhushan for ARPANET, FTP has variants such as FTPS (FTP over TLS) and SFTP (SSH File Transfer Protocol), which provide encryption and improved security.

FTP uses TCP port 21 for control commands and authentication, while TCP port 20 handles data transfers in active mode. Secure alternatives include FTPS (FTP over TLS), which uses ports 21 or 990, and SFTP (SSH File Transfer Protocol), which uses TCP port 22.

Active vs Passive Mode

FTP uses two modes to establish data connections - active and passive.
Active Mode - The client opens a port, and the server connects back to it. This often fails with firewalls (servers may block incoming connections).
Passive Mod - The server opens a port, and the client connects to it. This is more firewall-friendly.

To enable passive mode (default in many clients), run passive after connecting - same goes for active with the active command.

Additionally, when accessing the ftp server we can specify the -A flag for active mode.

Note: Sometimes there is no active command. You might want to run passive and turn it off. Even with fallback to active mode: off it might work.

ASCII vs. Binary Transfer Modes#

ASCII Mode - For text files (.txt, .csv, .html). Converts line endings (e.g., \n on Linux to \r\n on Windows).
Binary Mode - For non-text files (images, PDFs, executables, .zip). Transfers data as-is to prevent corruption.

Set modes with:
ftp> ascii # For text files
ftp> binary # or 'bin' for images, binaries (default in many clients)

Always use binary mode for non-text files! Transferring a .jpg in ASCII mode will corrupt it.

Techniques

Access

Connect to FTP anonymously - ftp <IP>

File transfer

Download a file - get [remote_file] [local_name]
Download multiple files - mget [pattern]
Upload a file - put [local_file] [remote_name] (make sure you’re in the binary mode)
Upload multiple files - mput [pattern] (make sure you’re in the binary mode)

For CWD the remote_name can be specified as . or just blank.

References