- Linux ftp command
- Syntax
- Options
- Aborting a file transfer
- File naming conventions
- File transfer parameters
- Environment
- Examples
- Related commands
- FTP Client Linux Command-Line Tutorial
- What Will We See Here?
- What Will We Need?
- FTP Command Syntax
- Creating an FTP Connection
- FTP Logging a Server
- Listing the FTP Commands
- Listing the Directory Contents
- Changing the Current Directory
- Uploading the Files
- Downloading the Files
- Conclusion
- About the author
- Ali Imran Nagori
Linux ftp command
The ftp command runs the classical command-line file transfer client, FTP. It’s an interactive text user interface for using the ARPANET (Advanced Research Projects Agency Network) standard File Transfer Protocol. It can transfer files to and from a remote network.
This page describes the version of ftp provided by package management on many GNU/Linux operating systems.
Syntax
ftp [-46pinegvd] [host [port]]
Options
-4 | Use only IPv4 to contact any host. |
-6 | Use IPv6 only. |
-p | Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default if invoked as pftp. |
-i | Turns off interactive prompting during multiple file transfers. |
-n | Restrains ftp from attempting «auto-login» upon initial connection. If auto-login is enabled, ftp checks the .netrc (see netrc) file in the user’s home directory for an entry describing an account on the remote machine. If no entry exists, ftp prompts for the remote machine login name (default is the user identity on the local machine), and, if necessary, prompt for a password and an account with which to log in. |
-e | Disables command editing and history support, if it was compiled into the ftp executable. Otherwise, does nothing. |
-g | Disables file name globbing. |
-v | Verbose option forces ftp to show all responses from the remote server, and report on data transfer statistics. |
-d | Enables debugging. |
The client host and an optional port number with which ftp is to communicate may be specified on the command line. If this is done, ftp immediately attempts to establish a connection to an FTP server on that host; otherwise, ftp enters its command interpreter and await instructions from the user. When ftp is awaiting commands from the user, the prompt ‘ftp>’ is provided to the user. The following commands are recognized by ftp:
Command arguments which have embedded spaces may be quoted with quote («) marks.
Aborting a file transfer
To abort a file transfer, use the terminal interrupt key (usually Ctrl-C). Sending transfers are immediately halted. Receiving transfers are halted by sending a ftp protocol ABOR command to the remote server, and discarding any further data received. The speed at which this is accomplished depends upon the remote server’s support for ABOR processing. If the remote server does not support the ABOR command, an ‘ftp>’ prompt does not appear until the remote server has completed sending the requested file.
The terminal interrupt key sequence is ignored when ftp has completed any local processing and is awaiting a reply from the remote server. A long delay in this mode may result from the ABOR processing described above, or from unexpected behavior by the remote server, including violations of the ftp protocol. If the delay results from unexpected remote server behavior, the local ftp program must be killed manually.
File naming conventions
Files specified as arguments to ftp commands are processed according to the following rules:
1. If the file name ‘—’ is specified, the stdin (for reading) or stdout (for writing) is used.
2. If the first character of the file name is ‘|’, the remainder of the argument is interpreted as a shell command. ftp then forks a shell, using popen with the argument supplied, and reads (writes) from the stdout (stdin). If the shell command includes spaces, the argument must be quoted; (e.g., «» ls -lt»«). A particularly useful example of this mechanism is «dir more«.
3. Failing the above checks, if «globbing» is enabled, local file names are expanded according to the rules used in the csh; c.f. the glob command. If the ftp command expects a single local file (e.g., put), only the first file name generated by the «globbing» operation is used.
4. For mget commands and get commands with unspecified local file names, the local file name is the remote file name, which may be altered by a case, ntrans, or nmap setting. The resulting file name may then be altered if runique is on.
5. For mput commands and put commands with unspecified remote file names, the remote file name is the local file name, which may be altered by a ntrans or nmap setting. The resulting file name may then be altered by the remote server if sunique is on.
File transfer parameters
The FTP specification specifies many parameters which may affect a file transfer. The type may be one of «ascii«, «image» (binary), «ebcdic», and «local byte size» (for PDP-10’s and PDP-20’s mostly). ftp supports the ascii and image types of file transfer, plus local byte size 8 for tenex mode transfers.
ftp supports only the default values for the remaining file transfer parameters: mode, form, and struct.
Environment
The ftp command makes use of the following environment variables:
HOME | The default location of a .netrc file, if one exists. |
SHELL | The default shell. |
Examples
ftp exampleftp.computerhope.com
The command above instructs ftp to attempt a connection to exampleftp.computerhope.com. Below is an example of what would be seen:
Connecting to exampleftp.computerhope.com. exampleftp.computerhope.com FTP server ready. Name: yourusername Password:
If your username and password are valid and entered correctly, you are successfully logged in:
Remote system type is UNIX. Using ASCII mode to transfer files. ftp>
Once at the ftp> prompt, you are placed in the default directory for the user you used to log in. The first thing you’d probably want to do is see what directory that is. To see the present working directory, use the pwd command like in Linux:
257 "/ftpdefaultdir" is current directory.
The number 257 is a numerical code. All FTP messages have a code number associated with them, and for technical reasons they are included with the messages from the server. The server lets you know you’re in the /ftpdefaultdir directory. Let’s see what files are in there, using the ls command:
This produces a file listing, like in Linux. You can change remote directories with cd. To change what directory you’re using on your local computer, you can use lcd for «local change directory.» Let’s say you want to get a file from the server named awesome.jpg, and download it to your local directory /home/myuser/images:
ftp> lcd /home/myuser/images
Local directory now /home/myuser/images
local: awesome.jpg remote: awesome.jpg 200 PORT command successful. 150 Opening ASCII mode data connection for awesome.jpg (352271 bytes).
Oops! That’s not quite right. JPEG (Joint Photographic Experts Group) images are binary files, not ASCII (text) files.
FTP supports two different types of file transfers, ASCII and binary. At login, the server told us it was currently in ASCII mode. Let’s change that to binary:
Using binary mode to transfer files.
bin is short for binary, and either command switches to binary mode. We can now do the same file transfer and the file comes through correctly.
Let’s switch to the remote directory all-images.
250-README for all-images 250- 250-This folder contains all the JPEG images for our project. 250- 250 CWD command successful.
This directory had a «README» message displayed by the FTP server every time you change it to your current directory. The server then lets you know the cd command was successful. Now let’s download every JPEG file using a wildcard. We can use the mget command, which allows us to get multiple files with one command:
ftp> mget *.jpg *.jpeg *.JPG *.JPEG
We now get all the jpeg files with the extensions JPG, JPEG, jpg, or jpeg.
If we have any files to upload to the server, we can use the commands put or mput to upload them. When we’re done, we can logout using the exit command.
Related commands
scp — Copy files securely over a network connection.
sftp — Conduct an interactive FTP session over a secure network connection.
FTP Client Linux Command-Line Tutorial
FTP (File Transfer Protocol) is a protocol for transferring files over a network. In the past, FTP was the preferred method for transferring the data between computers. However, this is no longer the case. The main problems that FTP used to have are solved by the newer protocols and programs.
What Will We See Here?
In this article, we will explore how to use the ftp command for remote system connection, file transfer, and managing the remote and local files and directories.
What Will We Need?
- Access to a remote FTP server from the local system. To keep it simple, we use a VirtualBox environment.
- FTP components are installed on both the local and remote systems.
NOTE: Since the FTP traffic is unencrypted, it is therefore an unsecured service. We thus recommend not to use it to transfer sensitive data over the internet and other unreliable networks.
FTP Command Syntax
The FTP command has the following syntax:
Here, [IP] denotes the IP address of the target remote system.
The FTP command uses the FTP protocol to connect a system to another system, which is usually a remote server, using the FTP protocol.
After a connection is established, users can also transfer files between the connected systems and manage the files and directories on them.
Creating an FTP Connection
We can create an FTP connection to a remote server using it’s IP address along with the FTP command:
For example, to connect to a remote server with the 192.168.56.10 IP address, run the following command:
When prompted, enter the credentials for the FTP user. Let’s see a live example of logging into an FTP server.
FTP Logging a Server
As soon as we establish a connection to the FTP server, we need to enter the username and the password to log in:
After entering the right credentials, we should be on the FTP interface:
Alternatively, we can first run the FTP command. Then, use the following command on the FTP interface:
From this interface, we can interact with the local machine as well as the remote server. We will soon see this in the following sections.
Listing the FTP Commands
Once we are inside the FTP interface, we can see and use all its commands. Let’s see all the supported commands by simply entering the “?”:
This represents us with many commands like dir, ls, disconnect, and so on. Let’s take a hand on a bunch of them.
Listing the Directory Contents
Let’s first see how we can list the content of the current directory on the remote system like the FTP server. Simply use the dir command here:
As mentioned earlier, we can manage the local machine from the remote machine. Let’s see how we can display the contents of the local directory:
The previous command displays the contents of our local system. To get more detailed listing, we can run the following command:
Similar to pwd which displays the current directory path, we can use the lcd command to display the same local path from the remote machine:
Changing the Current Directory
To navigate to the other directories on the remote server, we can use the usual cd command. For example, from the remote directories that are listed previously, we can change to the directory upload:
Uploading the Files
We can use the put command to send a single file to a remote server. Let’s see how to do this by simply uploading a from_local.txt local file:
After the command is successful, we will see a message like “Transfer complete”. By default, the file lands in the current directory on the remote server. However, we can customize this location by specifying the full path:
We can also use the dot (.) separator to denote the current path:
Let’s now see how to deal with multiple file uploads. We can use the FTP mput command to upload multiple files. For this, we need to specify the file names separated by spaces:
Interestingly, we can use the wildcards here if the file names share something in common. For example, to upload all the files with the name file but with different types, we can use the following command:
Before you can upload the files, you have to enter “yes” to confirm your action.
Downloading the Files
Let’s see how to download the files from the remote server to the local system. Instead of using put, we need to use its antonym like get. For instance, we can download/send a file, say file3.txt, to the local system as follows:
As seen in the uploaded scenario, we can also download a file to the directories other than the current directory on the local system. Just specify the full path on the local system:
Similar to mput, we can use the mget command to download multiple files. Again, let’s see it in action:
Also, the wildcards can simplify our work for similar types of files:
Conclusion
In this article, we cover a high-level overview of the FTP command on Linux. Besides the FTP client, there are other FTP clients for Linux such as Lftp, FileZilla, etc.
About the author
Ali Imran Nagori
Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.