How do I use FTP from a command line?

This page contains all information about how to connect to and utilize FTP from a command-line interface, such as the Linux shell or MS-DOS.

Note: FTP (File Transfer Protocol) is not secure transmission, which means that anyone intercepting your connection could access any data passed over it, including your account and password. We highly recommend using SFTP (Secure File Transfer Protocol) for more secure communication.

How do I use FTP from a command line

Connect using FTP

With the help of using FTP, to connect to another computer, you need to type FTP and hit Enter at the Linux shell, MS-DOS prompt or command line. You can use the open command in order to connect to the FTP server after you are in FTP, as demonstrated in the example below.

open ftp.example.com

You would replace example.com with the domain name or IP address of the location where you are connecting in the example above. An instance would be open 192.168.1.12

Note: The open command connects to the FTP server with the help of using TCP port 21 by default. If you need to connect to a different TCP port, insert the port number after the domain name or IP address in the open command.

You will see a username and password prompt on the screen once you have connected. Then, on the basis of your rights, the server makes it capable of browsing, transmitting, or receiving files once these credentials are entered. Additionally, some servers may allow anonymous logins via a guest account or an e-mail address.

Send and receive a file in FTP

Use the get command to download files from the server to your machine, as illustrated in the instance below. You would obtain the file myfile.htm in this case.

get myfile.htm

Tip

You can use mget and wildcards if you wish to get numerous files. For instance, you can type mget *.htm in order to get all files with the extension.htm. At the end, you can disable prompt with the help of typing prompt if you don-t want to be prompted each time a file is transmitted.

In order to transmit a file to another connected computer, you need to use the send command, as demonstrated in the example below. We are delivering myfile.htm to the current directory in this example.

send myfile.htm

It's critical to keep in mind that the files you transfer must be in your local working directory. In other words, the file must be saved in the directory where the FTP command was entered. Use the LCD command in order to change to the local directory where your files are kept. To change the local directory to the Windows directory on Windows, type lcd c:windows.

FTP commands

Each of the following commands may or may not work on the basis of your FTP version as well as the operating system. Are the commands available to you can be found by typing -help or a? The following is a list of FTP commands found in the Windows command-line FTP command.

CommandInformation
!The exclamation point command toggles between FTP and the operating system for a short time of period. Typing exit returns you to the FTP command line at the time you are using the operating system.
?Its use is to open the help screen.
appendThis command is used to append content to a local file.
asciiUse this command when you need to switch to ASCII transfer mode.
bellIts use is to turn bell on as well as off.
binaryThe use of this command is to switch to binary transfer mode.
byeIt is used to exits from FTP.
cdUsed for changing for directory.
closeIt is used to exits from FTP.
deleteAs implies its name, this command is used for deleting the files.
debugUse the debug command when you need to set debugging on or off.
dirLists files if a connection is established.

dir -C this command displays the list the files in wide format.

dir -1 lists the files in alphabetical order in bare format.

dir -r displays the contents of a directory in reverse alphabetical order.

dir -R displays the contents of the current directory and its subdirectories.

dir -S lists files in alphabetical order in bare format

disconnectThe work of this command is same as the commands close and bye, it is also used to exit from FTP.
getTakes a file from the computer that is connected.
globTurns on or off globing. When this option is disabled, wildcards are not allowed and the file name in the put and get commands is treated literally.
hashIt is used to turn on or off hash mark printing. When the device is turned on, a hash mark (#) is displayed for every 1024 bytes of data received
helpIf command is typed after help, you will see the help screen displays information about the command.
lcdIf lcd is typed alone, it displays the local directory, and it changes the local directory if the path is typed after lcd.
literalSends a one-line response to the connected computer in the form of a literal command.
lsIt displays lists of the files on the machine that is connected remotely.
mdeleteThis command is used to delete the multiple files.
mdirThis command displays the contents of many remote folders.
mgetIt is used to access several files.
mkdirIts use is to make a directory
mlsThis command displays the list contents of many remote folders.
mputThe word of this command is to send multiple files
openIts use is to open address.
promptIts use is to enable or disable the prompt.
putThis command is used to send one file.
pwdIt offers users the option to print working directory.
quitThe working of this command is to exit from FTP.
quoteUsed same as the literal command.
recvIt is used to receive file.
remotehelpUse this command when you need to get help from remote server.
renameIts use is to renames a file.
rmdirOn the remote computer, this command deletes a directory.
sendIt is used to send single file.
statusShows the status of the options that are currently enabled and disable.
traceUsed for Toggle packet tracing.
TypeThis command is used to set file transfer type.
userIts use is to send new user information.
verboseThis command is used to set verbose on or off.





Latest Courses