The FTP or File Transfer Protocol allows users to transfer files between an FTP server and a client over a network connection. Although there are numerous FTP clients to choose from, the Linux FTP command remains the most popular way of transferring files using FTP. This is especially true for system admins since you will mostly access your servers from a remote machine. Thus, you may use FTP for transferring large amounts of data between your FTP server and remote systems. In this guide, we will provide a practical introduction to FTP using a large number of essential commands. Bookmark this guide as a future reference if you’re already familiar with FTP.
Useful Linux FTP Commands
The below sections outline some useful Linux FTP commands that can be used for transferring a large amount of data over FTP. However, you should know that FTP connections are inherently insecure and do not offer any form of security, such as encryption. Thus, users must refrain from using FTP when exchanging sensitive documents and should use sftp or scp instead. Overall, ftp should be used for trivial tasks like downloading large media files, and so on.
1. Connect to FTP Servers
The first step of transferring files over FTP is to initiate an FTP connection. To do this, simply fire up your favorite Linux terminal emulator and type in one of the below commands.
$ ftp [ IP of FTP Server ] $ ftp [ NAME of FTP Server ]
So, you can start a connection via either using the IP of the FTP server or by just the name of the server. The below command shows a real-life example using a test server.
$ ftp 192.168.1.95
This is a test server on our local network. You can simply replace the IP with the address of your own FTP server. Once you press enter, it will ask for your login credentials. Type in the username and password in the following prompt to gain access to the server.
2. List Files On the Server
Once the connection is established, you may want to look around the server. This way, you can see the list of files available for downloading as well as the directory structure of the FTP server. Use the ls command to show a list of files and directories from within the FTP prompt.
The “ftp>” portion dictates that this command is being used from the FTP prompt rather than your standard Linux shell. Once you press enter, it will show all available files and directories under the current directory of the remote FTP server.
3. Navigate FTP Servers
The cd command allows users to navigate to and from directories within an FTP server. As you can probably tell, this is identical to the cd or change directory command available on your standard Linux installation.
ftp> cd public/
This will move the current working directory of your FTP connection to the public/ directory. You can move up and down using relative paths, as shown below.
ftp> cd ../bin
You may also use the Linux FTP command cdup for moving up a directory level. This is similar to the command “cd ../”.
4. Display Current Working Directory
When logged onto a remote FTP server, you will find many different files and directories. It is pretty easy to lost track of your current location when navigating through the Linux file system of the remote server. Luckily, you can print the working directory using the following simple command.
The ftp command pwd prints the present working directory of the remote filesystem. Like its shell counterpart, the FTP pwd offers a convenient means of navigation.
5. Download Files from FTP Server
The main reason most of us use FTP is for downloading files. It is very simple to do so from the Linux terminal. Simply type the command get in the FTP prompt of your terminal. The below example demonstrates this.
ftp> get test.zip
The above command copies the test.zip file from the present directory of the remote FTP server. This file will be stored inside the current working directory of your local machine. So, if you started the FTP connection from the ~/Downloads directory, the test.zip file will be copied there.
6. Download Multiple Files from FTP Server
Let’s say we want to download a collection of files onto our local workstation. It will be cumbersome to fetch each of these files one by one. Luckily, we can also perform batch downloads using a single command.
ftp> mget *.zip
The mget command downloads multiple files based on some pattern. The above example downloads all files that end with .zip from the remote server to our local machine. However, it will ask for confirmation each time it retrieves a new file. That’s why most FTP servers group together similar files as tar.gz or tar.bz2 files.
7. Upload Files to FTP Server
You can use the FTP sub-command put for uploading files from your local machine to the remote server. The below command illustrates this using a simple example.
ftp> put TEST.zip
This command will copy the TEST.zip file from the current working directory of your local machine to the remote server. However, in which directory of the remote server this file will be uploaded depends on your current location on the FTP server. So, if you run this command from the /uploads directory of the remote server, that will be the location for the uploaded document.
8. Upload Multiple Files to FTP Server
As with downloading, you can also upload more than one file using a single command. The mput command allows users to put multiple files to a remote server from a local machine.
ftp> mput test.jpg TEST.jpg
This command will upload the files test.jpg and TEST.jpg onto the current working directory of the remote server. You can use wildcards for matching multiple files. The following example illustrates how to upload multiple files based on a pattern.
ftp> mput *.jpg
This command will expand the filenames in your local directory and upload all .jpg files to the server.
9. Create Remote Directories
When uploading files to a remote FTP server, you might want to keep them inside a personalized directory. Plus, most admins outline specific rules for uploading files. The below example illustrates how you can create a new directory on the remote server.
ftp> mkdir test-dir
The mkdir command of the FTP CLI allows users to create a new directory inside the current working directory of the remote server. The above command will create a folder named test-dir. Now you can navigate into that directory and upload some test files.
10. Remove Remote Directories
You can also remove directories from the remote server, depending on your permission levels. Simply use the rmdir command to delete a remote directory.
ftp> rmdir test-dir
This command will delete the test-dir folder created in the earlier example. However, as discussed already, the ability to remove directories depends on the server configuration and is also subject to user permissions. Moreover, many FTP servers reject the deletion of directories that contain hidden folders, i.e- folders whose names start with a “.” symbol.
11. Change Directory in Local Machine
The files downloaded from a remote FTP server are stored in the directory from where the FTP connection was initiated. However, users can change this directory from within the Linux FTP command prompt. Check out the below example to see how this works.
$ ftp dlptest.com ftp> lcd ~/Downlaods
In the above example, the FTP connection was invoked from within the home directory of the local machine. Then we switched this to the ~/Downloads directory inside the local system. The lcd sub-command of the FTP CLI allowed us to do this. Now, any downloaded files will be stored inside ~/Downloads.
12. Remove Files from Remote Server
Given you have the required permissions, you can delete files from the remote FTP server. To do this, you will need to type the delete command, followed by the filename on the FTP prompt. The below example deletes a file called test.zip using this FTP command.
ftp> delete test.zip
This will remove the test.zip file from the current working directory of the remote server. You can not delete multiple files using a single delete command.
13. Remove Multiple Files from Remote Server
The mdelete command of the FTP CLI allows users to delete multiple files using a single command. It works very similar to mget and mput. The following example illustrates this.
ftp> mdelete *.torrent
When you run this command, it will delete each .torrent file from the current working directory of the remote server. However, the ability to delete files vary across servers and is subject to user permissions.
14. Rename Files on the Remote Server
Say you have uploaded a file to the server from your workstation and now want to change its name. The FTP rename command makes this very easy, as shown by the below example.
ftp> rename test.zip ftp-test.zip
The above command will rename the test.zip file on the FTP server to ftp-test.zip. So, the first argument for renaming is the current filename, and the last argument is the desired filename. The FTP server will return a status code of 250 if the rename is successful.
15. Change File Permissions
The Linux FTP command chmod allows users to change the permission settings of a file on the remote host. Simply enter chmod, followed by the permission mode in your FTP prompt. The below example provides a simple example of this command.
ftp> chmod 777 test.py
The above command will allow basically anyone to read, write, and execute the test.py file. The following command will allow only the owner to read, write, and execute this file. Everybody else would be allowed to only read the file.
ftp> chmod 744 test.py
Check our previous guide on the Linux file system to learn more about permissions and how different modes work.
16. Download Latest Updates
Many companies maintain an FTP server for transferring files back and forth among employees. Let’s say you have already downloaded a file, and some modifications were made to that by someone else. FTP offers a simple command which allows us to download a file only if it’s newer than the one that already exists on the local machine.
ftp> newer projects.tar.gz
The newer command will download the specified file only if it’s newer than the copy that already exists on the local machine. If there’s no such file on the host, then it will be considered as a new copy, and FTP will download it.
17. Append Data to Remote Files
Although we can not edit files directly on the FTP server, there is another way of updating these remote files. The append command of the FTP client allows users to append the data of a local document to a remote file. Check out the next example to see how this works.
ftp> append new.txt old.txt
This command will append the data contained by the local file new.txt to the remote file old.txt. So, the first argument for append is the local file, and the second argument is the remote file. The orientation is important here.
18. Notify After Each File Transfer
You can configure the FTP prompt to give notifications each time a file transfer operation is completed. The FTP sub-command bell allows users to do this.
This command takes no argument and simply rings a bell sound once a transfer is completed. Thus, it is suitable for tracking the progress of your transfers.
19. Write Directory Listing to Local Files
One interesting feature of the FTP utility is that it provides a dedicated command to save directory listing. This way, users can save the outline of a remote directory to a local file. This is very useful since you can not just pipe the output of the FTP ls command to a local document.
ftp> dir Remote-Dir/ Local-File
The dir command lists the contents of the remote directory “Remote-Dir/” and places the output to e local file “Local-File”. It will ask the user for confirmation before writing to the local filesystem.
20. Access Local Shell
As you should notice by now, it’s hard to access the Linux shell in your local machine once an FTP connection is established. This can hinder productivity and result in negative user experience. Thankfully, FTP provides a standalone command to access the local shell without having to terminate the FTP prompt.
ftp> ! [command [args ] ]
When you press “!” in the FTP prompt, it will open an interactive shell instance in the terminal. The FTP connection will still be available while you use this shell. Simply exit this local shell to get back to the FTP prompt. Optionally, you can also run commands directly from the FTP prompt by supplying its name and arguments after the “!” sign.
21. Set Transfer Mode to ASCII
FTP offers two different types of file transfer modes, ASCII and Binary. When you transfer a file between your local machine and the remote server, it selects the transfer type based on the filetype. For example, if you are downloading an image or a sound file, the transfer mode will be set to binary.
Typing the ASCII keyword in your FTP prompt will set the transfer mode to be ASCII type. It is suitable for transferring text data such as HTML files.
22. Set Transfer Mode to Binary
If the FTP server is configured to transfer files in the ASCII mode, it may hamper the transfer of binary data such as archives, executables, and so on. You can change the transfer mode to binary by using the following simple Linux FTP command.
Simply typing the binary keyword in the FTP prompt will switch the transfer mode to binary. You should only switch to and from different file transfer modes if you are unsure of how the default mode affects your data.
23. Toggle Carriage Return
Unix systems mark the end of ASCII files using the linefeed “n” character. However, Windows systems mark this using a combination of carriage return and linefeed “n + r” characters. This often leads to unwanted file corruptions when transferring text files between Unix and Windows platforms.
This command toggles the striping of carriage returns when transferring ASCII files, which is on by default. So, if you are having problems with maintaining newline sequences among the local host and the remote server, try toggling the carriage return using this command.
24. Turn On Debugging Mode
Linux FTP commands can be debugged to see which commands are sent to the remote server from your local machine. This is useful in a number of scenarios, including troubleshooting and auditing. It is also a great Linux hardening practice since you know exactly what is going on behind the scene.
Running the above command will turn on the debugging mode, which is disabled by default. Admins can also set an additional debug value. Greater debug values yield more detailed information.
ftp> debug [debug-value ] ftp> debug 3
25. Control the Progress Bar
You can use the FTP command hash for managing the progress bar for your data transfers. When you use it without any argument, this command toggles the printing for each transferred data block.
This will enable or disable a progress bar that shows a “#” symbol for each transferred block. By default, the size of a single block is 1024 bytes, but you can easily change it using an additional argument to hash. The following command sets the data block for the progress bar to be three Kilobytes instead of one.
ftp> hash 3K
You can use either k or K for Kilobytes, m or M for Megabytes, and g or G or Gigabytes.
26. Manage Inactivity Period
Most FTP servers set a default inactivity timer, after which the remote connection becomes closed. You can configure this timer using the idle command. The below example demonstrates this.
ftp> idle 100
This command sets the inactivity period to be 100 seconds. So, if you do not interact with the remote server for more than 100 seconds, the connection will be closed. If you omit the second argument, then the server will display the current inactivity period on the terminal.
27. Toggle Case Mapping
The Linux FTP command case allows users to toggle the case mapping of remote computer file names. When case is on, it will convert remote filenames containing all uppercase characters to lowercase in the local machine.
When you press enter, the prompt will notify you that case mapping enabled or disabled based on its prior state. Download some files whose names consist of only uppercases to see how the name is changed in your local system.
28. Toggle Interactive Mode
By default, FTP commands ask for confirmation during file transfer operations. However, this may often lead to unwanted experiences for the end-user. Luckily, it is very easy to enable or disable the interactive mode on demand.
The prompt command toggles the interactive mode that is set in the current FTP session. It will notify the user whether interactivity is currently enabled or disabled. We recommend users to perform some file transfers before and after running the prompt command to see how it works.
29. Write Macros
Macros are very useful for tackling everyday tasks. You can think of them as FTP functions and use them for automating your FTP workflow. You will need to write a macro before you can use it for data transfers. The macdef command allows users to do this.
ftp> macdef tasks Enter macro line by line, terminating it with a null line lcd /tmp/test prompt off mput * ls
Here, we have created a macro called tasks. It takes some Linux FTP commands on each line and is terminated when it reaches an empty line. You can combine any number of commands under a macro definition.
30. Run FTP Macros
Now that we have written our first macro let’s see how to use it for file transfers. Simply write a “$” followed by the macro name in your FTP prompt to run the macro.
ftp> $ tasks
This command will execute commands that make up the tasks macro. First, it changes the working directory of the local machine and turns off the interactive prompts. Then it will upload all files in the local directory to the server and finally print the directory listing for the remote server.
31. Toggle Filename Globbing
Filename globbing allows the Linux shell to expand filenames. This is how the shell expands file name patterns that contain wildcards. For mput, the expansion takes place on the local machine. On the other hand, the remote server is responsible for expanding the filenames for mget and mdelete.
When you toggle the globbing mode, the FTP prompt will display a notification stating whether globbing is enabled or disabled. If globbing is turned off, the filenames are not expanded and are simply taken literally.
32. Store List of Files inside a Directory
You can use the nlist command in FTP for retrieving the list of files inside a remote directory and save it to a local file for future exploration. The syntax for nlist is shown below.
nlist [remote-directory ] [local-file ]
You can omit the remote directory, and FTP will select the current working directory on the remote server for you. If the interactive prompt is on, it will ask you to confirm that the second argument is indeed the target file on the local machine.
ftp> nlist uploads/ list.txt
This command will save a list of all the files on the remote directory uploads/ to the local file list.txt. If you use “-“ in place of the local file, the output will be stored on the standard output.
33. Store List of Files inside Multiple Directory
What if you wanted to save a list of files inside multiple directories? The Linux FTP command mlist allows users to do exactly this. The difference between nlist and mlist is that the latter can work with multiple directories a the same time.
ftp> mlist audios/ videos/ images/ list.txt
This command will save a list of all the files contained by the directories audios/, videos/, and images/ inside the local file list.txt. Contrary to nlist, you must specify the local file for mlist.
34. Continue Paused Downloads
FTP allows users to continue downloads that are stopped due to network issues. The reget command works very similarly to get and checks if the local file is smaller than the remote file. If it is so, then reget assumes that the download was broken and continues downloading from that point.
ftp> reget music.tar.gz music.tar.gz
The above command first checks if the local file is smaller than the remote file or not. If they are of the same size, then it doesn’t retrieve the file. Else, the file will be downloaded from where it was left.
35. Display Last Modification Time
The FTP command modtime allows users to view when a file was last modified on the remote server. This can help users determine whether a file is newer than the one they already have on their personal machine. The syntax for the modtime command is below.
ftp> modtime test.zip
This command will print out the last modification time of the test.zip file. You can download the file if you find that it is newer than an existing copy.
36. Start a Secondary FTP Connection
Say you are connected to an FTP server and want to transfer some files from another remote FTP server. How can you do this without opening a new terminal session? FTP provides the proxy command to do exactly this.
The proxy command takes another FTP command as its argument. You can initiate a secondary FTP connection by using this command in the following way.
ftp> proxy open [ new ftp server]
Supply the name of the second server in place of the last argument and provide the necessary credentials. The second connection will be initiated successfully, and you can transfer files between the two servers now.
ftp> proxy get text.zip
This command will download the file test.zip from the second remote server to the first one. So, you will need to use the proxy command followed by the command that you want to run on the second server.
37. Display the Size of Remote Files
Sometimes you may want to see how much disk space remote files occupy before downloading them onto your local machine. The Linux FTP command size allows users to do this very easily. The syntax of the size command is shown below.
ftp> size archive.tar
This command will display the size of the remote file archive.tar in your FTP prompt. Simply replace archive.tar with any file name on the remote FTP server.
38. Display the Remote Systems Type
You can check the operating system that powers a remote FTP server by using the system command. It is useful when you are not sure which platform the FTP server is running.
The above command will show the remote systems’ type in your FTP prompt as well as the FTP request code. It can help users determine whether certain files like text documents will behave differently between the local system and the remote server.
39. Display the Remote Systems Status
When you face unwanted issues during data transfers, it can help if you check the system status of the remote server. This will show which FTP features are currently enabled or disabled as well as some additional information.
This command will show a lot of important information on your FTP prompt. Some of these include transfer mode and type, interactivity status, notification status, case mapping, hash printing, and so on.
40. Switch to a Different Account
If you have multiple user accounts on a remote server, you can easily switch back and forth among the. For this, you will need to use the Linux FTP command user. The following line shows the basic syntax for this command.
user user-name [password ] [account ]
Check out the below example to see how this works.
ftp> user admin ftp123
This command will try to switch to the admin account using the username “admin” and password “ftp123”. You can omit the username and password section if you want. In this case, an interactive prompt will ask you for the required credentials.
41. Toggle Storing of Unique Files on Local System
When you download a remote FTP file on your system, it will replace any existing file with the same name. This can lead to unwanted hassles down the line and can be easily evaded by using the runique command. When runique is enabled, it will download the new file and save it with a trailing suffix.
ftp> runique Receive unique on.
The trailing suffix will start with “.1” and can continue up to “.99”. It will print an error message after this. Receive unique is disabled by default, so check your servers’ status to see its current setting.
42. Toggle Storing of Unique Files on Remote System
The runique command only toggles the storing of unique files on the local system. However, there is another command to achieve the same effect on the remote server, the sunique command.
ftp> sunique Store unique on.
Now, you can upload multiple files with the same name to the server without having to overwrite the previous versions. However, the remote server must support the FTP protocol STOU for sunique to take effect.
43. Open FTP Connection from Prompt
Users do not need to start their FTP connection directly from their terminal session. It is possible to initiate an FTP connection from the FTP client. You will need to use the open command to do so. The following line shows the basic syntax for this command.
open host [port ]
Check out the below example to see how this works.
$ ftp ftp> open [ FTP Server ]
An interactive prompt will then ask for the credentials. Supply the username as well as the password to successfully connect to the remote server.
44. Connect Using IPv4
By default, FTP tries to connect with remote servers using the most stable network type. Since IPv4 is still the most prominent network, most servers will connect using IPv4. However, if your network supports both IPv4 and IPv6, you may want to connect remote servers via IPv4.
This command will choose IPv4 as the only addressing method for your remote transfers. You can also select it when invoking the FTP client by using the -4 option, as shown below.
$ ftp -4
45. Connect Using IPv6
Similarly, you can also set the network addressing to be IPv6 by using the ipv6 command in the FTP prompt. The following simple example demonstrates this.
Use the -6 option if you want to do this from the terminal session. You can run the Linux FTP command status for viewing which addressing mode is selected right now.
$ ftp -6
46. Toggle Verbose Mode
Verbose mode offers information regarding the remote server’s response as well as statistics after file transfers. By default, the verbose mode is set on. However, it can also hamper the user’s experience by showing almost the same information for each consecutive transfer. Users can easily disable the verbose mode in such scenarios.
ftp> verbose Verbose mode off.
Run this command again to enable verbose mode. You can also enable verbose mode when starting the FTP session.
$ ftp -v
47. Close FTP Connections
Once you are done with your data transfer, you can close the active connection. Closing the connection will not end the FTP session entirely. You will be taken back to the usual FTP prompt.
There is another Linux FTP command called disconnect for closing or disconnecting from the current remote server.
Both of the above commands do the same thing. They end the connection to the remote server but keeps the FTP session open.
48. End the FTP Session
You will want to terminate the FTP session when you are done with your file transfers. You can use one of three Linux FTP commands for ending your present FTP session. These are bye, exit, and quit.
ftp> bye ftp> exit ftp> quit
All of the above commands are similar and do the same thing. Enter any of them in your terminal to end the current FTP session.
49. Display the Help Page
The help page of FTP displays all the available FTP commands at your disposal. This is useful when you don’t remember a certain command and want to check out all the commands at a quick glance.
Typing help in your FTP session will show you all the available commands. There is a shorthand for this command, as demonstrated in the below example.
50. Display the Manual Page
The manual page for FTP shows a detailed list of all available commands as well as other command-line parameters. It also provides an in-depth discussion on how to use each command.
$ man ftp
Simply type in the above FTP command in your Linux terminal emulator to go to the man page. This is very useful when you want to learn more about a specific FTP command and its usage.
Linux FTP commands make it easy to perform file transfer operations from the command line. There are a large number of commands for different use cases. Our editors have compiled the most commonly used FTP commands for helping beginners get started with FTP as fast as possible. However, you should remember that FTP is not a secure way of transferring data. Anything you send over FTP connections can be captured using several open-source security tools for Linux. That is why you should only use FTP on your local network and for performing trivial tasks like downloading media files or backing up everyday data.