How to Use the Linux ftp Command to Transfer Files

FTP (File Transfer Protocol) is a standard network protocol used to transfer files to and from a remote server. While FTP has been largely replaced by secure alternatives, the command-line ftp client remains useful for accessing legacy servers and automated transfers in controlled environments.
This guide explains how to use the Linux ftp command to connect to a remote server, download files, and upload files.
Quick Reference
For a printable quick reference, see the FTP cheatsheet .
| Command | Description |
|---|---|
ftp hostname | Connect to an FTP server |
get file | Download a single file |
get file newname | Download a file and save it under a new name |
put file | Upload a single file |
put file newname | Upload a file and store it under a new name |
mget *.txt | Download multiple files |
mput *.txt | Upload multiple files |
lcd /path | Change local directory |
cd /path | Change remote directory |
ls | List remote directory contents |
binary | Switch to binary transfer mode |
ascii | Switch to ASCII transfer mode |
passive | Toggle passive mode (on by default) |
status | Show the current mode and settings |
prompt | Toggle per-file confirmation for mget/mput |
bye or quit | Close the connection |
Before You Begin
FTP traffic, including credentials, is transmitted in plain text and is not encrypted. For secure file transfers, use SCP or SFTP instead.
To transfer files, you must have at least read permissions on the source file and write permission on the target system.
When transferring large files, it is recommended to run the ftp command inside a screen
or tmux
session.
The directory from where you run the ftp command is the local working directory.
Installing the ftp Client
The ftp command is not always installed, especially on minimal and cloud images. If running ftp returns command not found, install the client package for your distribution.
Ubuntu, Debian, and Derivatives
sudo apt update
sudo apt install ftpOn current Ubuntu and Debian releases, ftp is a transitional package that installs tnftp, the FTP client from NetBSD. The ftp command runs tnftp, so all commands in this guide work the same way.
Fedora, RHEL, and Derivatives
sudo dnf install ftpFedora’s ftp package installs the Netkit client. The examples and output below use tnftp, as installed on Ubuntu and Debian. Basic transfer commands work in both clients, but URL downloads, the progress command, and the a/q confirmation responses require tnftp.
Establishing an FTP Connection
To connect to a remote FTP server, run the ftp command followed by the server IP address or domain name:
ftp 192.168.42.77If the connection is established, the server sends a 220 welcome message and you are prompted to enter your FTP username:
Connected to 192.168.42.77.
220 (vsFTPd 3.0.5)
Name (192.168.42.77:localuser): linuxizeThe welcome text depends on the FTP server software. The name in parentheses is your local username, which the client uses if you press Enter without typing a name.
After entering the username, type your password at the prompt:
331 Please specify the password.
Password:If the credentials are correct, the server displays a confirmation message and the ftp> prompt:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>anonymous as the username and your email address as the password.Transfer Modes: Binary vs ASCII
FTP supports two transfer modes:
- Binary mode: Transfers files byte-for-byte without modification. Use this for images, archives, executables, and any non-text file.
- ASCII mode: Converts line endings between systems (e.g.,
\r\non Windows to\non Linux). Use this only for plain text files.
Most modern FTP clients default to binary mode. To switch between modes at the ftp> prompt:
binaryasciiAlways use binary mode when transferring non-text files. Transferring a binary file in ASCII mode will corrupt it.
Downloading Files
Once you are logged in, your current working directory
is the remote user home directory. Files are downloaded to the local directory from which you started the ftp command.
To download files to a different local directory, use the lcd command:
lcd ~/DownloadsLocal directory now: /home/localuser/Downloadsftp can save files. Downloads work in your home directory, ~/Downloads, ~/Desktop, and /tmp, but saving into another subdirectory such as ~/backups fails with Permission denied. See the Troubleshooting
section for how to allow more directories.Download a Single File
Use the get command to download a file from the remote server:
get backup.ziplocal: backup.zip remote: backup.zip
229 Entering Extended Passive Mode (|||6948|)
150 Opening BINARY mode data connection for backup.zip (6673256 bytes).
100% |***********************************| 6516 KiB 888.34 MiB/s 00:00 ETA
226 Transfer complete.
6673256 bytes received in 00:00 (864.10 MiB/s)The 229 line shows that the client opened the data connection in passive mode. The progress bar tracks the download, and the last line reports the number of bytes received and the transfer rate.
To save the file under a different local name, pass the new name as the second argument:
get backup.zip backup-old.zipThe first line of the output confirms both names:
local: backup-old.zip remote: backup.zipDownload Multiple Files
Use the mget command to download multiple files. You can specify individual file names or use wildcard characters:
mget backup1.zip backup2.zipBy default, mget prompts for confirmation on each file:
mget backup1.zip [anpqy?]? y
229 Entering Extended Passive Mode (|||53270|)
150 Opening BINARY mode data connection for backup1.zip (7415 bytes).
100% |***********************************| 7415 58.92 MiB/s 00:00 ETA
226 Transfer complete.
7415 bytes received in 00:00 (7.29 MiB/s)
mget backup2.zip [anpqy?]? y
229 Entering Extended Passive Mode (|||16943|)
150 Opening BINARY mode data connection for backup2.zip (1415 bytes).
100% |***********************************| 1415 23.26 MiB/s 00:00 ETA
226 Transfer complete.
1415 bytes received in 00:00 (4.81 MiB/s)Type y to download the file or n to skip it. In tnftp, typing a downloads the current file and all remaining files without asking again, and q stops the whole mget operation.
To disable the per-file confirmation prompt, run prompt before using mget:
promptInteractive mode off.Run prompt again to re-enable confirmations.
Uploading Files
Upload a Single File
Use the put command to upload a file to the remote server:
put image.jpglocal: image.jpg remote: image.jpg
229 Entering Extended Passive Mode (|||16601|)
150 Ok to send data.
100% |***********************************| 96936 208.67 MiB/s 00:00 ETA
226 Transfer complete.
96936 bytes sent in 00:00 (135.54 MiB/s)To upload a file from a different local directory, use its absolute path.
To store the file on the server under a different name, add the remote name after the local one:
put image.jpg photo.jpglocal: image.jpg remote: photo.jpg
229 Entering Extended Passive Mode (|||19516|)
150 Ok to send data.
100% |***********************************| 96936 478.99 MiB/s 00:00 ETA
226 Transfer complete.
96936 bytes sent in 00:00 (154.33 MiB/s)The local image.jpg is now saved as photo.jpg in the remote directory. If a file with that name already exists on the server, it is overwritten.
Upload Multiple Files
Use the mput command to upload multiple files:
mput image1.jpg image2.jpgLike mget, the mput command prompts for confirmation on each file. Use prompt to toggle this behavior off.
Passive Mode
FTP uses two connections. Commands go over the control connection on port 21, and each file transfer or directory listing opens a separate data connection.
In active mode, the server initiates the data connection back to the client. This often fails when the client is behind a NAT router or firewall because the incoming connection is blocked. In passive mode, the client initiates both the control and data connections.
The ftp client on Ubuntu, Debian, and Fedora starts in passive mode and falls back to active mode if the server does not support it. The 229 Entering Extended Passive Mode line in the transfer output confirms that passive mode is in use.
To check the current mode, use the status command:
statusConnected and logged into 192.168.42.77.
No proxy connection.
Gate ftp: off, server (none), port ftpgate.
Passive mode: on; fallback to active mode: on.
Mode: stream; Type: binary; Form: non-print; Structure: file.
...The passive command toggles the mode. Since passive mode is already on, running it switches the client to active mode:
passivePassive mode: off; fallback to active mode: off.Run passive again to switch back. You can also set the mode when you connect. The -A option forces active mode, and -p enables passive mode:
ftp -A 192.168.42.77You need active mode only for old servers that do not accept passive connections.
Closing the Connection
When you are done, close the FTP connection with bye or quit:
quit221 Goodbye.Scripting FTP Transfers
With tnftp, you can download a file by passing its FTP URL on the command line. This works in a shell script or a cron job
without typing anything at the ftp> prompt. The URL examples in this section require tnftp; Fedora’s Netkit client does not support them.
To log in without a password prompt, store the credentials in a .netrc file in your home directory:
machine 192.168.42.77
login linuxize
password your_passwordThe client refuses to use a .netrc file with a password in it if other users can read it. Set the file permissions to 600:
chmod 600 ~/.netrcIf you skip this step, the automatic login fails with:
ftp: Error: .netrc file is readable by others
ftp: Remove password or make file unreadable by others.netrc file stores the password in plain text, and FTP sends it over the network unencrypted. Do not commit .netrc to version control. If you keep your dotfiles in a Git repository, add .netrc to .gitignore.With the .netrc file in place, the following script downloads a backup file into ~/Downloads using tnftp’s URL auto-fetch mode:
#!/bin/sh
cd ~/Downloads || exit 1
ftp ftp://linuxize@192.168.42.77/backup.zipThe client reads the password from the matching .netrc entry and transfers the file in binary mode. URL auto-fetch returns a nonzero exit status if the download fails, which becomes the script’s exit status. Feeding get and bye through a here document does not provide this check: bye can return status 0 even after a failed transfer.
When the output does not go to a terminal, as in a cron job, ftp does not print the progress bar and server responses. A successful transfer produces no output.
You can also run the URL command directly in your terminal. It logs in, downloads the file into the current directory, and exits:
ftp ftp://linuxize@192.168.42.77/backup1.zipConnected to 192.168.42.77.
220 (vsFTPd 3.0.5)
331 Please specify the password.
230 Login successful.
...
local: backup1.zip remote: backup1.zip
229 Entering Extended Passive Mode (|||28040|)
150 Opening BINARY mode data connection for backup1.zip (7415 bytes).
226 Transfer complete.
7415 bytes received in 00:00 (54.81 MiB/s)
221 Goodbye.With the matching .netrc entry, the client supplies the password automatically. Otherwise, it prompts you for one. The path in the URL is relative to the login directory of the FTP user. Do not put the password in the URL; it is saved in your shell history and is visible to other users in the process list.
Common FTP Commands
| Command | Description |
|---|---|
help or ? | List all available FTP commands |
cd directory | Change remote directory |
lcd directory | Change local directory |
ls | List files in the current remote directory |
pwd | Print the current remote working directory |
mkdir directory | Create a directory on the remote server |
delete file | Remove a file on the remote server |
rmdir directory | Remove a directory on the remote server |
rename old new | Rename a file on the remote server |
status | Show current connection and transfer settings |
hash | Toggle hash mark display during transfers |
progress | Toggle the transfer progress bar (tnftp only) |
Troubleshooting
Connection refused or timed out
The FTP server may not be running, the port may be blocked by a firewall, or the IP address is incorrect. Verify the server is listening on port 21 and that your firewall allows outbound connections to it.
ftp: connect: No route to host
A network-level issue is preventing the connection. Check your network connectivity and DNS resolution.
Transfer hangs or times out after connecting successfully
The data connection is being blocked. Run status and check the Passive mode line. If passive mode is off, a NAT router or firewall is probably blocking the server’s connection back to your client; run passive to turn it back on. If passive mode is already on, the server’s firewall is likely blocking the port range it uses for passive connections, and the server administrator needs to open it.
Downloads fail with “Permission denied”
On Ubuntu 25.10 and later, the error looks like this even though you own the local directory:
ftp: Can't open `backup.zip': Permission deniedThe AppArmor profile for the client allows downloads only into your home directory, ~/Downloads, ~/Desktop, ~/tmp, and /tmp. Use lcd ~/Downloads before downloading, or allow another directory by adding a rule to the local override file:
echo 'owner @{HOME}/backups/** rw,' | sudo tee -a /etc/apparmor.d/local/tnftp
sudo apparmor_parser -r /etc/apparmor.d/tnftpReplace backups with the directory you want to use. The change takes effect for the next ftp session.
Downloaded file is corrupted or has wrong size
The file was likely transferred in ASCII mode instead of binary mode. Run binary before downloading non-text files.
mget or mput asks for confirmation on every file
Run prompt to toggle off the interactive confirmation. This is especially useful when downloading or uploading many files at once.
FAQ
Is FTP still safe to use?
FTP transmits data and credentials in plain text. It should only be used on trusted networks or for non-sensitive data. For secure transfers, use SFTP
or SCP
.
What is the difference between FTP and SFTP?
FTP is an unencrypted protocol that uses port 21. SFTP
runs over SSH (port 22) and encrypts all data and credentials. Despite similar names, they are entirely different protocols.
How do I transfer files without being prompted for each one?
Run prompt at the ftp> prompt to disable interactive mode. After that, mget and mput will transfer all matching files without asking for confirmation.
What is the difference between active and passive FTP mode?
In active mode, the server connects back to the client for data transfer, which often fails behind firewalls or NAT. In passive mode, the client initiates both connections, making it more compatible with modern network setups. The ftp client on current Linux distributions uses passive mode by default.
How do I download a whole directory with ftp?
The ftp client cannot download directories recursively. The mget * command downloads only the files in the current remote directory and skips subdirectories. To copy a full directory tree, use wget
, for example wget -r -l inf --user=linuxize --ask-password ftp://192.168.42.77/public_html/, or the mirror command in lftp. With Wget, -r enables recursion and -l inf removes the default limit of five directory levels.
Conclusion
The ftp command provides a straightforward way to transfer files to and from remote servers. For secure transfers over untrusted networks, use SFTP
or SCP
instead.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page