The basics of ftp and sftp

ftp.jpg

There’s many ftp clients on all operating systems, but in the Linux world we come across many machines where we have no gui interface and it’s helpful to have the knowledge on how to utilize ftp and ssh’s secure implementation, sftp, on the command line. FTP functionality comes built into most linux systems and you should not have to install anything to get started here.

FTP

First make sure you’re in a directory where you have permission to the files within it.

To Connect to an ftp server we simply:

ftp ip-address or ftp servername.com

If you’ve already executed “ftp” without specifying a host you can do:

ftp> open servername.com

Usually at this point you will be prompted for a username and password if one is required. Once logged in you’ll find many of the linux commands to naviage through filesystems work within ftp such as pwd, ls, cd, etc..

You can specify the username when logging on:

ftp username@servername.com

To Download files we use the “get” command, such as below:

(You will have to navigate to the folder you know the file resides in or know the path and the file name.)

ftp> get file.tar.gz

If you ‘get’ files like above the file name will not change. If you want the file name to change merely specify the destination name you’d like the file to have.

ftp> get file.tar.gz new_filename.tar.gz

To Download more than one file at a time we use “mget” (mget stands for multiple get)

For example, if we have file1.txt, file2.txt, and file3.txt we could specify each file:

ftp>mget file1.txt file2.txt file3.txt

or you can use wildcards

ftp> mget file*

To upload files to the host machine we use the “put” command

(The put command works just like the get command)

ftp> put file.tar.gz

To upload multiple files we use mput

ftp> mput file1.txt file2.txt file3.txt

or again, the mput command like the mget command supports wildcards

ftp> mput file*

Navigate Local Directories from the FTP Session

lpwd – will print the current directory you are in on the local machine, l stands for local, pwd is the standard command that prints the current directory to the screen

lcd /home/username/folder1 – will change the to the folder1 directory on the local machine, adjust the path as needed.

!ls – will list your directory contents in the folder you are currently in on the local machine

!bash – will take you to your local bash shell on the local machine and make the ftp session run in the background. Typing “exit” will take you back to your ftp session.

Other Helpful Commands within the FTP Session

bye or exit – will exit the ftp session

SFTP

Secure file transfer protocol(sftp) is a terminal program that encrypts the files that you send and recievei to a remote system. The Open-ssh package comes with three client programs. One of which is sftp.

sftp is a secure form of the ftp command.Whenever a user opens up a regular ftp session or most other TCP/IP connections, the entire transmission made between the host and the user is sent in plain text.Anyone who has the ability to snoop on the network packets can read the data, including the password information.If an unauthorized user can login, they have the oppurtunity to compromise the system.

sftp is similar to ftp: sftp username@ip_address at which point it will prompt you for your password. Then you receive an sftp prompt. For then on you use the same commands as in an ftp session: get,put, etc. Unfortunately sftp does not support mget or mput. It’s common practice to place your files in a compressed archive such as a tar.gz file, a zip file, or a rar file for transfer over commandline sftp. If you need a reminder which commands are available type “help” at the sftp> prompt.

When using ssh’s sftp instead of the ftp, the entire login sesion, including transmission of password, is encrypted.It is therefore much more difficult for an outsider to observe and collect passwords from a system using ssh/sftp sessions.

Gui sftp and ftp clients

Now that we’ve covered how to perform these on the commandline, you may want to check out the following gui ftp clients (capable of ssh, sftp, ftp, and others). Most of these are available in most Linux repo’s, but just in case you can download them where linked.

FileZilla – a cross platform ftp client

gFTP – a gtk based ftp client

kasablanca - a qt based ftp client

Related Posts

Comments are closed.