Showing posts with label FTP. Show all posts
Showing posts with label FTP. Show all posts

Tuesday, 12 June 2018

FTP (File Transfer Protocol) Command Examples

FTP Command, FTP Learning, LPI Guides, LPI Study Materials, LPI Tutorials and Materials

The FTP (file transfer program) utility is used to transfer files between a local machine and remote network machine Using the File Transfer protocol. In simple terms it transfers / copies files between two computers. You can transfer files between unix systems and also non-unix systems like windows operating system using FTP.

The FTP command is simple to use and easy to learn. Let see useful examples of FTP command in detail.

FTP Command Examples:


If you are using windows operating system, open the command prompt and practice the below FTP commands. If you are using unix or linux operating systems, just simply type the ftp command on the terminal.

1. Connecting to Remote Host


First you need to connect to a remote host before doing any operations. You can use any one of the following methods to connect to a remote host. First method is

> ftp remote-server-name
connected to remote-server-name
User-Name:
Password:
ftp>

Once the ftp connects to the remote server name, it will prompt you to enter the user name and password. After successful login, your terminal or prompt changes to "ftp>".

Another method is to use the open option with ftp command. This is shown below:

>ftp
ftp>open remote-server-name
connected to remote-server-name
User-Name:
Password:
ftp>

If the ftp command fails to connect to the remote server, then you will get the below error:

ftp: connect: Connection refused

2. Copy file from remote machine to local machine.


The get option is used to download or transfer a file from the remote system to the local system.

ftp> get windows-cleveland.bat

This will download the specified file (windows-cleveland.bat) from the remote systems current directory.

3. Copying multiple files from remote machine to local machine.


You can use the mget to transfer multiple files from the remote host to local host.

ftp>mget *.png

This will download all the png images to the local machine.

4. Transferring file from local server to remote server


The put option is used to copy the file from the local host to the remote host.

ftp>put linux-virtual-server.rpm

This command puts the rpm file into the remote machine.

5. Transferring multiple files to the remote server.


You can use the mput option to transfer more than one file from local system to the remote system.

ftp>put *.rpm

6. Executing commands in remote machine.


After connecting to the remote network machine using the ftp, you can run commands like ls to list the files, cd to change directory and many more.

ftp> ls

This will list the files and directories in the remote machines current directory.

7. Executing commands in local machine.


Once you have connected to the remote host, to run the commands on local machine you need to exit from the ftp connection. Instead of this, there is a way to run commands on local host without exiting from the ftp connection. Use the ! symbol before the command you want to run.

ftp> !ls

Now this will list the files in the local machines current directory.

8. Changing the file transferring mode.


You can change the file transfer modes to ascii and binary modes. Use the below commands to change the mode.

ftp>ascii
ftp>binary

9. Deleting files on remote machine


You can use the delete or mdelete to remove a single file or multiple files in the remote machine.

ftp>delete linux-dedicated-server.dat
ftp>mdelete *.dat

10. Disconnecting from ftp connection.


Use the quit command to close the ftp connection.

ftp>quit

11. Using FTP command in batch scripts


The following script reads the instructions from the dat file and executes them on the remote machine.

echo "Ftp command batch script"
echo "start"
ftp -s:instructions.dat remote-host
echo "End"

The contents of the instructions.dat file is

FTP Command, FTP Learning, LPI Guides, LPI Study Materials, LPI Tutorials and Materials

user
password
cd /var/tmp
put oracle_storage.exe
quit

12. Getting the help about ftp command.


To know more about the ftp command, just type the help on the prompt. It will display the options/commands that you can use with ftp command.

ftp>help
Commands may be abbreviated.  Commands are:

!       disconnect mdelete  preserve  runique
$       edit       mdir     progress  send
account exit       mget     prompt    sendport
append  form       mkdir    proxy     site
ascii   ftp        mls      put       size
bell    get        mode     pwd       sndbuf
binary  gate       modtime  quit      status
bye     glob       more     quote     struct
case    hash       mput     rcvbuf    sunique
cd      help       msend    recv      system
cdup    idle       newer    reget     tenex
chmod   image      nlist    rename    trace
close   lcd        nmap     reset     type
cr      less       ntrans   restart   umask
debug   lpwd       open     rhelp     user
delete  ls         page     rmdir     verbose
dir     macdef     passive  rstatus   ?

Friday, 9 February 2018

Example Uses of the Linux Command FTP

Linux Command, FTP, LPI Certifications, LPI Guides, LPI Tutorials and Materials

FTP is the simplest and most familiar file transfer protocol that exchanges files between a local computer and a remote computer or network. Linux and Unix operating systems have built-in command line prompts you can use as FTP clients for making an FTP connection.

Warning: An FTP transmission is not encrypted. Anyone who intercepts the transmission can read the data you send, including your username and password.

For a secure transmission, use SFTP.

Establish an FTP Connection


Before you can use the various FTP commands, you must establish a connection with the remote network or computer. Do this by opening a terminal window in Linux and typing ftp followed by a domain name or an IP address of the FTP server, such as ftp 192-168-0-1 or ftp domain.com. For example:

ftp abc.xyz.edu

This command attempts to connect to the ftp server at abc.xyz.edu. If it succeeds, it asks you to log in using a username and password. Public FTP servers often allow you to log in using the username anonymous and your email address as a password or with no password at all.

When you log in successfully, you see an ftp> prompt on the terminal screen. Before you go any further, get a list of the available FTP commands using the help function. It is useful because depending on your system and software, some of the FTP commands listed here may or may not work.

FTP Command Examples and Descriptions


The FTP commands used with Linux and UNIX differ from the FTP commands used with the Windows command line. Here are examples that illustrate typical uses of the Linux FTP commands for remotely copying, renaming, and deleting files.

 ftp> help

The help function lists the commands that you can use to show the directory contents, transfer files, and delete files.

The command ftp> ? accomplishes the same thing.

 ftp> ls

This command prints the names of the files and subdirectories in the current directory on the remote computer.

ftp> cd customers

This command changes the current directory to the subdirectory named customers, if it exists.

 ftp> cdup

This changes the current directory to the parent directory.

 ftp> lcd [images]

This command changes the current directory on the local computer to images, if it exists.

 ftp> ascii

This changes to ascii mode for transferring text files. ASCII is the default on most systems.

 ftp> binary

This command changes to binary mode for transferring all files that are not text files.

 ftp> get image1.jpg

This downloads the file image1.jpg from the remote computer to the local computer. Warning: If there already is a file on the local computer with the same name, it is overwritten.

 ftp> put image2.jpg

Uploads the file image2.jpg from the local computer to the remote computer. Warning: If there already is a file on the remote computer with the same name, it is overwritten.

 ftp> !ls

Add an exclamation mark in front of a command executes the specified command on the local computer. So !ls lists the file names and directory names of the current directory on the local computer.

 ftp> mget *.jpg

With the mget command. you can download multiple images. This command downloads all files that end with .jpg.

ftp> rename [from] [to]

The rename command changes the file named [from] to the new name [to] on the remote server.

ftp> put local-file [remote-file]

This command stores a local file on the remote machine. Send local-file [remote file] does the same thing.

 ftp> mput *.jpg

This command uploads all the files that end with .jpg to the active folder at the remote machine.

ftp> delete remote-file

Delete the file named remote-file on the remote machine.

 ftp> mdelete *.jpg

This deletes all files that end with .jpg in the active folder on the remote machine.

ftp> size file-name

Determine the size of a file on the remote machine with this command.

ftp> mkdir [directory-name]​

Make a new directory on the remote server.

 ftp> prompt

The prompt command turns interactive mode on or off so that commands on multiple files are executed without user confirmation.

 ftp> quit

The quit command terminates the FTP session and exits the FTP program. The commands bye and exit accomplish the same thing.