How to use the FTP command in Linux?

How to use the FTP command in Linux?

To move files between your computer and a remote server, Linux has an ftp command. It connects to a File Transfer Protocol (FTP) server and gives you a prompt for browsing the server’s folders and transferring files.

This guide covers moving files with get and put once you’re connected, and why plain FTP shouldn’t carry passwords or private files.

What is the FTP command in Linux?

The ftp command opens an interactive client session with a File Transfer Protocol (FTP) server. You enter commands at its prompt to list remote files, move between directories, and transfer files.

An FTP session separates the command connection from the data connection. The first carries commands and replies, while the second carries directory listings and file contents, so a session can connect successfully yet fail when a transfer starts.

ProtocolWhat it means for a transfer
FTPFile-transfer protocol without encryption by itself.
FTPSFTP protected with TLS when both endpoints support and configure it.
SFTPFile transfer over SSH, separate from FTP and FTPS.

FTP commands such as get and put act on the server’s files, but local path commands act on the Linux machine running the client. Keeping those two sides separate prevents a download or upload from targeting the wrong directory.

What you need before connecting

You need an FTP client, a server hostname or address, an account allowed to access that server, and permission to read or write the target directory. Installing the client does not create or configure an FTP server.

  1. Check whether the client is installed by running ftp -? or starting ftp.
  2. On Ubuntu, the repository package is named tnftp. If it is missing, install it with sudo apt install tnftp. Other distributions can package a different FTP client.
  3. Ask the server owner whether the endpoint requires FTP, explicit or implicit FTPS, or SFTP. Do not send a password or private file through plain FTP.

The local client’s help lists commands without connecting to a server. I ran the command below and saw the client list get, put, lcd, cd, passive, and quit.

Linux FTP client interactive command list
The local FTP client lists its commands before any server connection.

Use the FTP client to move files

Start with one session and keep track of which commands refer to the server and which refer to your Linux machine.

These examples show client syntax. Server replies depend on its permissions and configuration.

Step 1: Connect to the FTP server

At your shell prompt, open the client with the server hostname. If the server requires login details, enter them at its prompt. Never put a password directly in the command because it can be saved in shell history or exposed in process details.

ftp ftp.example.com

After login, the prompt changes to the FTP client’s prompt. If the server uses a non-default port, check the client’s manual for its connection syntax because FTP implementations handle ports and URLs differently.

Step 2: Check remote and local directories

Use pwd and ls to inspect the server’s current directory and its contents. Use cd to change that remote location, while lcd changes the local directory where downloads are saved and from which uploads are read.

ftp> pwd
ftp> ls
ftp> cd /remote/path
ftp> lcd /local/path

The Linux ls command lists local files in a shell, but ls at the FTP prompt lists remote files. The existing listing below is an example of the remote view.

FTP client listing remote files
Example remote directory listing from an FTP session.

Use lcd to change the local directory, then use cd to change the server directory. Create a local directory with the mkdir command before pointing lcd at it. FTP mkdir creates a directory on the server instead.

ftp> mkdir incoming
ftp> cd incoming
FTP client creates a remote directory
Example server response to a remote directory creation request.
FTP client changes the remote working directory
Example response after changing the remote working directory.

Step 3: Download files from the server

Run get with a remote filename to save that file into the current local directory. Add a second name when you want the local copy to use a different filename.

ftp> get report.csv
ftp> get report.csv local-report.csv
FTP client output after a get command downloads one file
Example FTP server replies after the client requests a download. The response reports transfer completion, not file integrity.

Use mget with names or a wildcard supported by the client and server for several files. Check the matched names before accepting prompts because wildcard expansion can select more files than intended.

ftp> mget *.txt
FTP client output for downloading matching files with mget
Example output from an FTP client’s multiple-file download command.

After the transfer, check the local destination with your shell’s ls command and inspect the file if correctness matters. A success reply from an FTP server reports its transfer status, not that the downloaded file is the version you expected.

Step 4: Upload files to the server

Use put with a file that exists in the current local directory. The optional second name selects the filename stored on the server.

ftp> put local-report.csv
ftp> put local-report.csv report.csv
FTP client output after put sends a local file to the server
Example FTP server replies after a single-file upload.

Use mput for multiple local files. Confirm the local directory with lpwd or change it with lcd. Review filenames before accepting transfer prompts.

ftp> lpwd
ftp> mput *.csv
FTP client output for uploading several local files with mput
Example output for an FTP client’s multiple-file upload command.

If the server allows remote file management, rename can change a remote filename and delete can remove it. Treat delete as a destructive server operation and confirm the remote directory and filename before running it.

ftp> rename old-name new-name
ftp> delete old-name
FTP client rename command and server response
Example response to a remote rename command.

Use ls after a rename or deletion to inspect the resulting remote listing. These older screenshots are examples, not output from the server you are connected to.

FTP listing after a remote file rename
Example listing used to confirm the renamed remote filename.
FTP client delete command and server response
Example response after requesting deletion of a remote file.
FTP listing after a remote file deletion
Example listing used to confirm that a remote filename is no longer present.

Step 5: Finish the session safely

Type bye, quit, or exit to close the interactive client. The Linux shell prompt returns after the FTP session ends.

ftp> bye
FTP client exits an interactive session
Example FTP session exit command.

When a connection or transfer fails

A successful login proves that the command connection worked. File transfers also need a usable data connection and server permission for the requested operation.

SymptomCheckNext move
ftp: command not foundThe client package is missing or uses another package name.Install the distribution’s FTP client package, or use its documented SFTP client.
Login succeeds but listing or transfer stallsThe FTP data connection may be blocked or misrouted by a firewall or NAT.Ask the server administrator which passive or active mode and port range the service supports. The client has a passive command, but mode support is server-dependent.
get or put reports a missing fileThe remote path and local path may refer to different directories.Check pwd and lpwd, then use cd or lcd on the correct side.
Text file contents changeASCII mode can convert line endings. Binary mode transfers bytes without text conversion.Use binary for archives, images, executables, and files that must remain byte-for-byte unchanged.

The screenshot shows that this client has a passive command, but its behavior depends on the connected server. Without TLS, FTP does not protect the password or file contents from network observers.

For command-line transfers over SSH, see the SSH command, SCP, or the site’s guide to installing an SFTP client. These are separate from FTP. You need an SSH account and server support.

Choose encryption before transferring sensitive files

Plain FTP is a legacy choice for trusted networks and services that require it, not a safe default for passwords or private data. When the server offers SSH file transfer, choose SFTP. For HTTPS downloads, use the curl command with the HTTPS URL.

SFTP speaks the SSH file-transfer protocol, so it does not use the FTP server or FTP commands. Confirm the remote account and destination with the server owner, then connect with the SFTP client.

FTP command in Linux questions

How do I install the FTP command in Linux?

Install an FTP client package from your distribution. On Ubuntu, tnftp is available as a client package and can be installed with sudo apt install tnftp. This installs a client, not an FTP server.

How do I download a file with the FTP command?

Connect to the server, move to the directory that contains the remote file, and run get filename at the FTP prompt. The downloaded file is written to the client’s current local directory, which you can inspect or change with lpwd and lcd.

How do I upload a file with FTP in Linux?

Connect to the server, change to the intended remote directory with cd, and run put filename for a file in the current local directory. Use lcd to select another local directory before uploading.

Is SFTP the same as FTP?

No. SFTP is a file-transfer protocol carried over SSH. FTPS is FTP protected with TLS, while plain FTP does not encrypt credentials or file contents by itself.