How to use FTP from a command line

Updated: 03/05/2023 by Computer Hope
FTP cloud

To connect to and use FTP from a command line interface, like MS-DOS or the Linux shell, click a link below for instructions.

Tip

If you're not familiar with navigating a computer using a command line, see: How to FTP.

Note

FTP is not an encrypted transmission, which means any data sent over it, including your username and password, could be read by anyone intercepting your transmission. If you want a more secure transmission, we suggest using SFTP (Secure File Transfer Protocol).

Connect using FTP

To connect to another computer using FTP at the MS-DOS prompt, command line, or Linux shell, type FTP, and press Enter. Once in FTP, use the open command to connect to the FTP server, as shown in the following example.

open ftp.example.com

In the example above, you'd substitute example.com for the domain name or IP address of where you are connecting. An example would be open 192.168.1.12.

Note

By default, the open command uses the TCP (Transmission Control Protocol) port 21 to make the FTP connection. If a different TCP port is needed to connect, enter the port number after the domain name or IP address in the open command.

Once connected, a username and password prompt appears. Once these credentials are entered, the server lets you browse, send, or receive files, depending on your rights. Some servers may also allow anonymous logins using guest or an e-mail address.

Send and receive a file in FTP

To get files from the server onto your computer, use the get command, as shown in the following example. In this example, you would get the file myfile.htm.

get myfile.htm
Tip

To get more than one file, use mget and wildcards. For example, if you wanted to get all files that end with .htm, you could type mget *.htm. Finally, if you do not want to be prompted as each file is sent, make sure to type prompt to disable prompting.

Use the send command, as shown in the following example, to move a file to another connected computer. In this example, we are sending the myfile.htm to the current directory.

send myfile.htm

It is important to realize that the files sent must be in your local working directory. In other words, the directory you were in when you typed the FTP command. To change to the local directory containing your files, use the lcd command. For example, in Windows, you'd type lcd c:\windows to set the local directory to the Windows directory.

FTP commands

Depending on the version of FTP and the operating system, each of the following commands may or may not work. Typing -help or a ? lists the commands available to you. Below is a general description of FTP commands available in the Windows command line FTP command.

Command Information
! The exclamation point command switches temporarily from FTP to operating system. When using the operating system, typing exit takes you back to the FTP command line.
? Access the help screen.
append Append text to a local file.
ascii Switch to ASCII (American Standard Code for Information Interchange) transfer mode.
bell Turns bell mode on or off.
binary Switches to binary transfer mode.
bye Exits from FTP.
cd Changes directory.
close Exits from FTP.
delete Deletes a file.
debug Sets debugging on or off.
dir Lists files if connected.

dir -C lists the files in wide format.
dir -1 lists the files in bare format in alphabetic order
dir -r lists directory in reverse alphabetic order.
dir -R lists all files in current directory and subdirectories.
dir -S lists files in bare format in alphabetic order.
disconnect Exits from FTP.
get Grabs file from the connected computer.
glob Sets globbing on or off. When turned off the file name in the put and get commands is taken literally and wildcards are not used.
hash Sets hash mark printing on or off. When turned on, for each 1024 bytes of data received, a hash mark (#) is displayed.
help Access the help screen and displays information about command if command typed after help.
lcd Displays local directory if typed alone, or if path typed after lcd, changes local directory.
literal Sends a literal command to the connected computer with an expected one line response.
ls Lists files of the remotely connected computer.
mdelete Multiple delete.
mdir Lists contents of multiple remote directories.
mget Get multiple files.
mkdir Make directory.
mls Lists contents of multiple remote directories.
mput Sent multiple files
open Opens address.
prompt Enables or disables the prompt.
put Send one file.
pwd Print working directory.
quit Exits from FTP.
quote Same as the literal command.
recv Receive file.
remotehelp Get help from remote server.
rename Renames a file.
rmdir Removes a directory on the remote computer.
send Send single file.
status Shows status of currently enabled and disabled options.
trace Toggles packet tracing.
Type Set file transfer type.
user Send new user information.
verbose Sets verbose on or off.