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 |
put file | Upload a single file |
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 |
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.
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, a welcome message is displayed and you are prompted to enter your FTP username:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 21:35. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (192.168.42.77:localuser): linuxizeAfter entering the username, type your password at the prompt:
Password:If the credentials are correct, the server displays a confirmation message and the ftp> prompt:
230 OK. Current restricted directory is /
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 ~/ftp_downloadsDownload a Single File
Use the get command to download a file from the remote server:
get backup.zip200 PORT command successful
150-Connecting to port 60609
150 6516.9 kbytes to download
226-File successfully transferred
226 2.356 seconds (measured here), 2.70 Mbytes per second
6673256 bytes received in 2.55 seconds (2.49 Mbytes/s)Download 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? y
200 PORT command successful
150 Connecting to port 52231
226-File successfully transferred
226 0.000 seconds (measured here), 31.51 Kbytes per second
14 bytes received in 0.00058 seconds (23.6 kbytes/s)
mget backup2.zip? y
200 PORT command successful
150-Connecting to port 59179
150 7.2 kbytes to download
226-File successfully transferred
226 0.000 seconds (measured here), 16.68 Mbytes per second
7415 bytes received in 0.011 seconds (661 kbytes/s)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.jpg200 PORT command successful
150 Connecting to port 34583
226-File successfully transferred
226 0.849 seconds (measured here), 111.48 Kbytes per second
96936 bytes sent in 0.421 seconds (225 kbytes/s)To upload a file from a different local directory, use its absolute path.
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
By default, FTP uses active mode, where 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.
Passive mode solves this by having the client initiate both the control and data connections. To toggle passive mode:
passivePassive mode on.If you experience “connection refused” or timeout errors during transfers, switching to passive mode usually resolves the issue.
Closing the Connection
When you are done, close the FTP connection with bye or quit:
quit221-Goodbye. You uploaded 0 and downloaded 6544 kbytes.
221 Logout.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 |
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
This is almost always a passive mode issue. The server is trying to open a data connection back to your client, but a NAT router or firewall is blocking it. Run passive at the ftp> prompt to switch to passive mode.
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.
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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page