How do I use FTP from a command line?

Question

How do I use FTP from a command line?

Answer

Note: FTP is not an encrypted transmission, which means any data sent over it, including your username and password could be read by anyone who may intercept your transmission. If you're wanting a more secure transmission we suggest using SFTP.

Connect using FTP
Send and receive a file in FTP
FTP commands

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> type:

open ftp.example.com

In the above example, you'd substitute example.com for the name of your domain you're wanting to connect to. In addition to the domain name the IP address of the computer you're trying to connected to can also be typed typed in, for example, open 192.168.1.12.

Once connected you will be asked for a username and password. If these are entered properly you'll be successfully connected to the server where you can browse the files, send files, or receive files depending on your rights. Some servers may also allow anonymous logins you can connect to these computers using guest / e-mail address.

Send and receive a file in FTP

To get files from the server onto your own computer use the get command as shown in the below example. In this example you'd get the file myfile.htm.

Tip If you want 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 being sent make sure to type prompt to disable prompting.

get myfile.htm

To send a file from your computer to the computer you are connected to assuming you have the rights use the send command as shown in the below example. In this example we're sending the myfile.htm to the directory we're currently in.

send myfile.htm

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

FTP Commands

Depending upon the version of FTP and the operating system being used, each of the below commands may or may not work. Generally typing -help or a ? will list the commands available to you. Below is a general description of FTP commands available in the Windows command line FTP command.

CommandInformation
!Using this command you will have the capability of toggling back and forth between the operating system and ftp. Once back in the operating system generally typing exit will take you back to the FTP command line.
?Access the Help screen.
appendAppend text to a local file.
asciiSwitch to ASCII transfer mode
bellTurns bell mode on / off.
binarySwitches to binary transfer mode.
byeExits from FTP.
cdChanges directory.
closeExits from FTP.
deleteDeletes a file.
debugSets debugging on / off.
dirLists files if connected.

dir -C = Will list 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 sub directories.
dir -S = Lists files in bare format in alphabetic order.
disconnectExits from FTP.
getGet file from the computer connected to.
globSets globbing on / off. When turned off the file name in the put and get commands is taken literally and wildcards will not be looked at.
hashSets hash mark printing on / off. When turned on for each 1024 bytes of data received a hash-mark (#) is displayed.
helpAccess the Help screen and displays information about command if command typed after help.
lcdDisplays local directory if typed alone or if path typed after lcd will change local directory.
literalSends a literal command to the connected computer with an expected one line response.
lsLists files of the remotely connected computer.
mdeleteMultiple delete.
mdirLists contents of multiple remote directories.
mgetGet multiple files.
mkdirMake directory.
mlsLists contents of multiple remote directories.
mputSent multiple files
openOpens address.
promptEnables/disables prompt.
putSend one file
pwdPrint working directory
quitExits from FTP.
quote Same as the literal command.
recvReceive file.
remotehelp  Get help from remote server.
renameRenames a file.
rmdirRemoves a directory on the remote computer.
sendSend single file.
statusShows status of currently enabled / disabled options
traceToggles packet tracing.
typeSet file transfer type.
userSend new user information.
verboseSets verbose on / off.

Additional information

  • Category
  • FTP help
  • Solved?
  • Were you able to locate the answer to your question?