How To

ftp Command in Linux: Connect to Servers and Transfer Files

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.

How to Use the ftp Command in Linux

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:

  • Binary mode — transfers files byte-for-byte without modification. Use for images, archives, executables, and any non-text file
  • ASCII mode — converts line endings between systems (Windows \r\n to Linux \n). Use for plain text files only

Most 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.

Download and Upload Files: get, mget, put, and mput

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.

Binary Mode, Passive Mode, and Closing the Session

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.

Cyber Defence

Recent Posts

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

1 week ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

1 week ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

1 week ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

2 weeks ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

2 weeks ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

2 weeks ago