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

ss Command in Linux: Display Socket Statistics and Connections

The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…

3 minutes ago

lsmod Command in Linux: List and Inspect Kernel Modules

The lsmod command in Linux lists all currently loaded kernel modules. It reads /proc/modules — a virtual file maintained…

13 minutes ago

rename Command in Linux: Batch Rename Files with Perl Regex

The rename command in Linux renames multiple files at once using Perl regular expressions. Unlike mv, which handles…

18 minutes ago

pgrep Command in Linux: Find and Filter Running Processes

The pgrep command in Linux finds the PIDs of running processes based on a name or other…

21 hours ago

unlink Command in Linux: Remove a Single File or Symlink

The unlink command in Linux removes a single file by deleting its directory entry. It is a…

21 hours ago

How to Check Open Ports in Linux: nmap, netcat, and Bash

When troubleshooting a network connection or configuring a firewall, the first question is whether a…

21 hours ago