The ftp command in Linux connects to a remote FTP server and transfers files. FTP transmits everything in plain text: credentials and file data are both unencrypted. For transfers over untrusted networks, use SFTP or SCP instead. On trusted internal networks or for legacy server access, ftp remains practical.
Connect by passing the server IP address or hostname:
bashftp 192.168.42.77
If the connection succeeds, the server shows a welcome message and asks for a username and password. After login, you land at the ftp> prompt. For servers that allow anonymous access, use anonymous as the username and your email address as the password.
The local working directory is the directory from which you launched ftp, not your home directory. Use lcd to change it before starting a download:
bashlcd ~/ftp_downloads
FTP supports two transfer modes:
\r\n to Linux \n). Use for plain text files onlyMost modern FTP clients default to binary mode. Transferring a binary file in ASCII mode corrupts it. Switch modes at the ftp> prompt:
bashbinary # switch to binary modeascii # switch to ASCII mode
Run status at the ftp> prompt to confirm the current transfer mode and connection settings before starting a large transfer.
For large transfers, run the ftp command inside a screen or tmux session. If your SSH connection drops, the transfer continues in the background.
To download a single file:
bashget backup.zip
To download multiple files with a wildcard:
bashmget *.zip
By default, mget prompts for confirmation before each file. Run prompt at the ftp> prompt to disable interactive mode — all matching files will transfer without asking. Run prompt again to re-enable confirmations.
To upload a single file:
bashput image.jpg
To upload multiple files:
bashmput *.jpg
mput respects the same prompt toggle. To upload a file from a directory other than your current local directory, pass its full absolute path to put.
FTP uses two connection modes for data transfers:
Active mode is the default. The server opens the data connection back to the client. This is blocked by most NAT routers and firewalls.
Passive mode has the client initiate both the control and data connections. It works with modern network setups.
If a transfer hangs or times out after the initial connection succeeds, the cause is almost always active mode being blocked. Toggle passive mode at the ftp> prompt:
bashpassive
This resolves most timeout and connection refused errors that appear during the transfer, not during login.
Close the session when done:
bashquit
Use binary mode for all non-text files, enable passive if transfers hang after connecting, and toggle prompt off before batch mget or mput operations. For secure transfers, use SFTP or SCP. Leave a comment below if you run into any issues.
The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…
The lsmod command in Linux lists all currently loaded kernel modules. It reads /proc/modules — a virtual file maintained…
The rename command in Linux renames multiple files at once using Perl regular expressions. Unlike mv, which handles…
The pgrep command in Linux finds the PIDs of running processes based on a name or other…
The unlink command in Linux removes a single file by deleting its directory entry. It is a…
When troubleshooting a network connection or configuring a firewall, the first question is whether a…