We all know the abbreviation FTP, which stands for File Transfer Protocol. An old but still widely used technology for transferring files between two computers over a TCP/IP network.
Most of us use some kind of utility or file manager module to work with this protocol. But let's imagine a situation where you need to access an FTP server via the command line. There won't be any panels with a list of files and "Copy" and "Delete" buttons there. (By the way, I often work through the command line myself - it's actually simpler and even faster for me - whenever I need to do or check something on FTP.)
So, the command for working with FTP is the same on both Windows and Unix (including Linux Debian, CentOS, Ubuntu, RHEL, FreeBSD, etc.) - it's simply called "ftp".
Simply connecting to a specific server - the syntax won't differ either:
ftp 192.168.0.1
But tricks like auto-login and automatically accepting or sending files are somewhat OS-specific, and we won't cover them here. Instead, let's go over what can actually be done within the session itself via the command line - and the commands themselves, of course.
So let's begin. This reference lists the most frequently used commands that will let you freely communicate with any server with any set of options.
CommandsOPEN
Connect to the specified server.
ftp> open 192.168.0.1
The server will then ask you for a login and password.
CLOSE or DISCONNECT
Close the connection with the current FTP server.
ftp> close
BYE or QUIT
Close the connection and exit the FTP utility.
ftp> bye
USER
Log in on the given server as the specified user (you must already be connected).
ftp> user myusername
where instead of "myusername" substitute the username you're logging in as. The FTP server will ask you for the password for this user before letting you in.
LS or DIR
Show the list of files and directories in the current folder on the server.
ftp> ls
MLS or MDIR
Export the list of files from several directories into a file on
your computer.
ftp> mls dir1 dir2 dir3 mylocalfile.txt
CD
Go to the specified folder on the server.
ftp> cd ../another/folder
A special case of this command: CDUP - go to the parent directory - the same as "CD ..":
ftp> cdup
LCD
Go to the specified folder on
your computer.
ftp> cd /home/myusername/ftp
PWD
Show the current path (current folder) on the FTP server.
ftp> pwd
GET or RECV
Download the specified file from the FTP server into the current folder on your computer.
ftp> get myftpfile.txt
MGET
Download several files from the FTP server into the current folder on your computer.
ftp> mget file1.txt file2.txt
mget file1.txt? y
mget file2.txt? y
NEWER
Download the specified file from the FTP server to your computer only if your local file is older (i.e. the remote file is newer).
ftp> newer myfile1 myfile1
Here the first argument is the file name on the server, and the second argument is the file name on your computer.
PUT or SEND
Upload the specified file from your computer to the FTP server.
ftp> put mylocalfile.txt
MPUT
Upload several files from your computer to the server.
ftp> mput myfile1.txt myfile2.txt
mput myfile1.txt? y
mput myfile2.txt? y
DELETE
Delete the specified file on the server.
ftp> delete remotefile.txt
MDELETE
Delete several files on the server.
ftp> mdelete file1 file2
MKDIR
Create a directory on the server.
ftp> mkdir mynewdir
RMDIR
Delete a directory on the server
ftp> rmdir mydir
Those are the main commands. There are, of course, more of them, but this particular set will let you successfully work with any FTP server from the command line.
You can, as always, learn more from the help. To do this, type "HELP" at the FTP command line and get a list of supported directives.
Example FTP sessionHere's an example of a short FTP session in which we connect to the server, create a folder "newfiles", and upload the file "binfile.bin" into that folder.
$ ftp 192.168.0.1
...
ftp> mkdir newfiles
...
ftp> cd newfiles
...
ftp> put binfile.bin
...
ftp> bye
Comments