Linux ftp command tutorial
Linux ftp command tutorial
Today I will go through a series of FTP commands from a linux command line, I will show you really simple how to use this without using a 3rd party software like FileZilla for instance. Don’t get me wrong, I recommend Filezilla at any time, but for those who want to use the built-in FTP client from Ubuntu or any other linux operating system, this tutorial could come in handy.
Connect to FTP server
Using the below commands you can connect to any FTP server.
1 2 3 |
ftp ftp.domain.com ftp 192.168.1.100 ftp user@ftp.domain.com |
The end result will be similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 2 of 50 allowed. 220-Local time is now 11:24. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (ftp.domain.com:user): xxxx 331 User xxxx OK. Password required Password:****** 230 xxxx login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files. ftp> |
You will have to enter a username there and a password and you will be logged in. Once you are logged in, you will see the ftp> prompter there waiting for new commands.
Listing files and folders on FTP
You need to use the ls command to list the content from your location, a sample result is below:
1 2 3 4 5 6 7 8 9 |
ftp> ls 229 Entering Extended Passive Mode (|||52582|) 150 Opening ASCII mode data connection for '/bin/ls'. total 10 drwxrwxr-x 2 0 5 512 Sep 19 2013 test drwxr-xr-x 3 1345 1345 512 Sep 21 2013 public_html drwxr-xr-x 3 1345 1345 512 Oct 5 2013 backup drwxr-xr-x 4 1345 0 512 Oct 18 2013 www 226 Transfer complete. |
Change directory on FTP
To change the directory you are in, you only need to use the command cd and the name of the folder you want to enter. See below example:
1 2 |
ftp> cd www 250 CWD command successful. |
Upload content to FTP
To upload content to your FTP account, one at a time from the local systems to the remote ftp server, enter the command put with the local file name:
1 |
ftp> put file_name |
Upload Multiple Files to FTP
To upload multiple files from the local system to the remote ftp server use the command mput below:
1 2 |
ftp> mput * ftp> mput *.php |
Keep in mind that you will be prompted to confirm you want to upload the files.
Download / Copy files from FTP
To download one file at a time from the remote ftp server to our local system we would use the get command:
1 |
ftp> get file_name |
An output similar to below you should be able to see:
1 2 3 4 5 6 |
local: file_name.doc remote: file_name.doc 229 Entering Extended Passive Mode (|||56053|) 150 Opening BINARY mode data connection for 'file_name.doc' (2047 bytes). 100% |*************************************************| 2047 15 KiB/s 00:00 ETA 226 Transfer complete. 2047 bytes received in 00:04 (15 KiB/s) |
Change Local Directory and print remote directory on FTP
You would need to change the local path for you to be able to copy your files or upload your files to your desired location, you can do this using the lcd command:
1 2 |
ftp> lcd /home/www Local directory now /home/www |
A similar output you would see if say you want to print the remote directory of your current path, using the command pwd:
1 2 |
ftp> pwd 257 "/www" is your current location |
The pwd command prints the current path directory of your remote location, on your FTP account.
Download Multiple Files on FTP
Similar to uploading, you need to use the mget command as follows to copy content from your remote ftp server to the local system. You may be prompted for a yes/no (Y/N) answer before transferring each file (you can disable prompt by passing the -i option to ftp client when connecting). To download all files, enter:
1 |
ftp> mget * |
To download all php files (ending with .php extension), enter:
1 |
ftp> mget *.php |
Disable prompting from FTP client
The ftp command prompt sets interactive prompting,
- on which enables prompting so that you can check download
- off allows the commands to act without the need of interaction.
1 2 |
ftp> prompt on ftp> mput *.php |
This is valid for uploading and downloading from your FTP server.
Delete file from FTP
To delete a file from your current remote directory use the delete command:
1 2 |
ftp> delete file_name ftp> delete red.jpg |
Create a new folder on your FTP account:
To create a new folder or directory on your FTP account, you need to use the bellow command mkdir:
1 2 3 4 |
ftp> mkdir folder_name ftp> mkdir images ftp> cd images ftp> pwd |
Delete a Directory
To remove or delete a directory is a bit different, but using the command rmdir you can do this also:
1 2 3 |
ftp> rmdir dirName ftp> rmdir images ftp> ls |
Change the transfer mode
To set the transfer mode to ASCII, enter:
1 |
ftp> ascii |
ascii is the default transfer mode and good this is very good for text files. To set the mode of file transfer to binary, enter:
1 |
ftp> binary |
The binary mode is recommended for almost all sort of files including images, archive files and much more. The binary mode provides less chance of a transmission error.
That’s about it with this tutorial, got it pretty long it seems. See you again in our next tutorial