Home Tools to copy from local to server scp, rsync, ftp, sftp, lftp, ..etc
Post
Cancel

Tools to copy from local to server scp, rsync, ftp, sftp, lftp, ..etc

draft blog about different ways to transfer data between machine and server

In today’s blog I’m going to show you how can easily transfer data between your local machine and your server easily and in a secure encrypted way.

Agenda:

  • Normal FTP
  • using SCP
  • GUI clients/tools (Termius, fileZilla, ..)
  • using native ssh file transfer
  • using SFTP
  • using rSync

Normal FTP

We will being with the most common way - FTP - which is less secure and robust. FTP is a standard protocol which uses TCP/IP port 21 to transfer data between or client/server over network in an insecure way- later in the blog I will introduce the new SFTP that is capable of transferring data in secure way based on SSL/TLS. Let’s begin with establishing a connection through command line.

To open FTP tool, in your terminal write the following command:

FTP

Now instantiate a connection to your server using the following native FTP command

open <your_server_ip_address>

open 192.168.101

You can combine the above two commands in one command:

ftp 192.168.101

It will prompt you for your username then your password, type your username (or press return to enter the username same as your local one).

After instantiating a connection you will be ready to transfer files either download or upload files. To get help while you are on the ftp server type:

help

or simply type ‘?’ – a question mark.

at this part will end the section of normal FTP without exposure to any transfer commands and move to SFTP which will have the same file transfer commands.

SFTP

SFTP (secure file transfer protocol) is an enhanced and secure version of FTP. It uses SSL/TLS which means all your transferred data is secure and encrypted.

To Connect to a FTP server using SFTP using the command line:

SFTP <your_server_ip_address>

you will be prompted for username and password, type them to instantiate a SFTP connection.

Note that in this version (SFTP) you can also use ssh keys to login to your server:

ssh -i "path_to_private_ssh_key" <username>@<remote_server_ip_address>

Navigation with SFTP

the commands of SFTP navigation is quite similar to the ones you use in shell. But the trick here in FTP is that you work on the server while also knowing that you can transfer files from your local machine to this server i.e. you will navigate on the server and also on the client and the commands to navigate directories either on the server or on your local machine are quite similar.

For example if you want to print the current working directory (on your remote server):

pwd

but the one you use to print the local current working directory:

lpwd

the difference is the letter ‘l’ at the begging of ‘pwd’ which refers to ‘local’

to change to another directory on the server:

cd <directory_name>

but to change to another directory on your local machine:

lcd <directory_name>

Again as you notice that the difference is the letter ‘l’ at the begging.

To list the the files and directories on the remote server:

ls

To list the files and dirs on your local machine:

lls

you can also pass arguments like: ‘ls -lah’ or ‘lls -lah’

Transferring files using SFTP

To download a file from your server to your local machine use the ‘get command’:

get <file_name>

To download multiple files from your remote server on your local machine use the ‘mget’ command:

mget file1.txt file2.txt file3.txt

note that get works with files only, if you want to download a directory, pass the ‘-r’ argument to download a full directory recursively:

get -r <dir_name>

To maintain permissions and mos of the files or directory, pass the ‘-P argument’

get -Pr <dir_name>

To upload single file from your local machine to your remote server:

put <file_name_on_your_local_machine>

To upload multiple files from your local machine to your remote server use the ‘mput’ command:

mput file1.txt file2.txt file3.txt

Also this command ‘put’ works only with single files, so if you want to upload a complete directory, pass the argument ‘-r’:

put -r <path_to_dir _on_local_machine>

You can also use ‘-P’ to preserve mods and file permissions

TBC

This post is licensed under CC BY 4.0 by the author.