UNIX Communication Commands | FTP Command | FTP Command Examples

FTP Command :

In my previous article i have explained about the Ping command of unix/linux with different examples. In this article i will try to explain the FTP Command in unix in detail with real examples in day to day life.FTP stands for File transfer protocol which  is used to transfer the file from one server to another server location.FTP command is so useful as it allows you to store and retrieve files from any computer in the world.There are 2 types of FTP :

1.FTP : which is a simple File Transfer Protocol

2.SFTP:which is Secured File Transfer Protocol

FTP is most preferred protocol for data transfer among the computers.

Following are different usages of FTP :

1.Log in and establishing connection with the remote host computer.

2.Upload the Files

3.Download the Files.

4.Navigating through the different directorties

5.Browsing contents through directories.

I will explain the different usages of FTP Command with real world examples.The FTP commands are applicable to SFTP also so wherever FTP is mentioned user can use that same commands for SFTP also.

Example 1 : Connecting to the FTP Server

The basic question is how to connect to FTP server.You can open the connection with the remote host with using the IP of target PC or hostname of the PC. To check the hostname of the PC following command is used :

Example :

$hostname

Output :

PC102323

User can use 2 different commands to connect through FTP server.

Syntax :

Command 1 :

$FTP IP/Hostname

Example:

$FTP 10.20.208.110

User can directly connect through the FTP command using the Hostname or IP address.

Command 2 :

$FTP

ftp>Open IP/Hostname

User can connect to FTP server and then use open command to connect with the FTP server.The server will ask the username and password while connecting to the server.

Example 2 :Downloading File using FTP :

After connecting to FTP server the question  is how to download the file in FTP.When user connect to the FTP server the set of commands need to use for different operations.To download the file from FTP server the GET command is used.

There are 2 modes available to download the file. One is Binary mode (for non-text files) and ascii mode (for text files).

Example :

To download the file and save it with another name.The File named complexsql.html is saved as complexsql1.html.

Change mode to ASCII:

ftp>ascii
ftp> get compexsql.html complexsql1.html
Fetching /home/complexsql.html to complexsql1.html
/home/complexsql.html

Example 3: Change the FTP mode to ASCII to Binary mode to transfer non-text file.

When user needs to download the non text files then there is need change the mode from ASCII  mode to binary mode..

ftp> binary
200 Type set to I.

Example 4:Upload the file to FTP Server

User needs to use the PUT command to upload the file to FTP server.

Example:

ftp> put filename
ftp> put complexsql.html

Example 5: List all files in FTP server

You can view all the files and directories of FTP server using ls command.

Example:

ftp>ls

It will  list all files on ftp server.

Example 6:  Help Command

If you want to check the different FTP commands  just connect to  FTP server and use help command or ? command to check different FTP commands.

Syntax :

ftp > Help Command Name

Example:
ftp> Help Put

The above command will show the Put command help.

Example 7:  Changing directory using cd Command

Just like a simple unix command of changing directory.User can change the directory using cd command.There are 2 directories one is remote directory and other directory is local directory.

ftp> pwd

“/home” is current directory.

ftp> cd directory1

CWD command successful.

“/home/directory1” is current directory.

ftp> pwd 257

“/home/directory1” is current directory.

Example 8 : Change local directory with using lcd command

FTP Command

User can use lcd command to change local directory.

Note :

  • Shell : executing ! takes you to the shell.
  • FTP Prompt : prompt starts with ftp> is ftp prompt.
  • Shell Prompt : prompt starts with is shell command line.

ftp> !

$ pwd /home/Amiet/

FTP $ exit exit

ftp> lcd /tmp Local directory now /tmp

ftp> !

$ pwd

/tmp

Example 9 : Downloading multiple files

User can download the multiple files using the mget command.User can use the globs to download multiple files.

Example :

If user want to download all jpg files from ftp server then use mget with * .

ftp> mget *.jpg

The above command will download all the jpg files from remote server. After downloading the files if user wants to show the files which are downloaded then use mls command as follows :

ftp> mls.jpg

Example 10 : Uploading multiple files

User can upload the multiple files using mput command of FTP.The mput command works similar to mget command.

Example :

Following command will upload all the jpg files from local server to remote server.

ftp> mput *.jpg

Example 11 : Close FTP connection

After opening the FTP connection user needs to close it to connect with another connection.User needs to use the close command to close FTP connection.

ftp> open ftp.complexsql.com

Already connected to complexsql.com, use close first.

ftp> close

221 Goodbye.

ftp> open ftp.anonymous.com

These are some important examples of FTP command which are very useful in our day to day life.Kindly comment in comment section if you have any suggestions.

 

About admin 136 Articles
Oracle Consultant with Vast Experience in Oracle BI and SQL PLSQL Development

Be the first to comment

Leave a Reply

Your email address will not be published.


*