How do I use FTP from a command line?
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 want a more secure transmission, we suggest using SFTP.
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.
Note: By default, the open command uses the TCP port 21 to make the FTP connection. If a different TCP port is needed for connecting to the domain name or IP address you are using, enter the port number after the domain name or IP address in the open command.
Once connected, a username and password prompt will appear. Once these credentials have been entered, the server allows you to 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.
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.
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 following example. In this example, we are sending the myfile.htm to the current directory.
It is important to realize that the files being sent must be in your local working directory, which is 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, in Windows, you'd type lcd c:\windows to set the local directory to the Windows directory.
Depending on the version of FTP and the operating system being used, each of the following commands may or may not work. 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.
|!||This command toggles back and forth between the operating system and FTP. Once back in 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 transfer mode|
|bell||Turns bell mode on or off.|
|binary||Switches to binary transfer mode.|
|bye||Exits from FTP.|
|close||Exits from FTP.|
|delete||Deletes a file.|
|debug||Sets debugging on or off.|
|dir||Lists 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 subdirectories.
dir -S lists files in bare format in alphabetic order.
|disconnect||Exits from FTP.|
|get||Grabs file from the computer to which you are connected.|
|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 will change 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.|
|mdir||Lists contents of multiple remote directories.|
|mget||Get multiple files.|
|mls||Lists contents of multiple remote directories.|
|mput||Sent multiple files|
|prompt||Enables or disables the prompt.|
|put||Send one file.|
|pwd||Print working directory.|
|quit||Exits from FTP.|
|quote||Same as the literal command.|
|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.|
- See FTP definition for additional information and related links.