Transfer Files Between Servers in Linux

SSH File Transfer Protocol also called Secret File Transfer Protocol or Secure FTP, or SFTP is a network protocol that provides file access, file transfer, and file management functionality over the network. In this post i will show how to transfer the files using sftp command on Linux Red Hat Enterprise Linux 6 (RHEL 6). Assumed that the following servers presented on your network.

Transfer Files Between Servers using sftp Command

rhel 6 = 192.168.2.43 –> Local working directory: /root/rhel6
CentOS 5.7 = 192.168.2.45 –> Remote working directory: /root/centos57

1. From local working directory rhel6, sftp to centos57 (192.168.2.45) using root with password as below :

[root@rhel6 ~]# sftp root@192.168.2.45
Connecting to 192.168.2.45...
The authenticity of host '192.168.2.45 (192.168.2.45)' can't be established.
RSA key fingerprint is 59:4a:13:85:f0:60:9d:c1:1d:49:95:c7:58:56:5d:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.45' (RSA) to the list of known hosts.
root@192.168.2.45's password:

2. Change the directory on the local computer using lcd command. In this case i will Change the directory to /root/rhel6 :

sftp> lcd /root/rhel6

3. Show the current directory (present working directory) on the local computer. In this case local working directory is /root/rhel6 :

sftp> lpwd
Local working directory: /root/rhel6

Display local directory listing

sftp> lls
testing.tar.gz

4. Copy/upload a file from the local computer to the remote computer using put command. This scenario consider equivalent with uploading process. At first, only testfile1 and testfile2 exist in /root/centos57. In this case, i will copy the testing.tar.gz from /root/rhel6 to /root/centos57 :

sftp> put testing.tar.gz
Uploading testing.tar.gz to /root/centos57/testing.tar.gz
testing.tar.gz                                                    100%  169     0.2KB/s   00:00

Display remote working directory :

sftp> pwd
Remote working directory: /root/centos57

Display remote directory listing :

sftp> ls
testfile1       testfile2       testing.tar.gz

5. Change the directory on the remote computer using cd command. In this case i will Change the directory to /root/centos57 :

sftp> cd /root/centos57

6. Show the current directory (present working directory) on the remote server. In this case remote working directory is /root/centos57 :

sftp> pwd
Remote working directory: /root/centos57

Display remote directory listing :

sftp> ls
testfile1  testfile2

7. Copy/download a file from the remote computer to the local computer using get command. This scenario consider same as downloading process. At first, only testing.tar.gz exist in /root/rhel6. In this case, i will copy the testfile1 from /root/centos57 to /root/rhel6 :

sftp> get testfile1
Fetching /root/centos57/testfile1 to testfile1
/root/centos57/testfile1                                          100%    5     0.0KB/s   00:00

Display local working directory :

sftp> lpwd
Local working directory: /root/rhel6

Display local directory listing :

sftp> lls
testfile1  testing.tar.gz
sftp>

8. Display this help text :

sftp> help
Available commands:
bye                                Quit sftp
cd path                            Change remote directory to 'path'
chgrp grp path                     Change group of file 'path' to 'grp'
chmod mode path                    Change permissions of file 'path' to 'mode'
chown own path                     Change owner of file 'path' to 'own'
df [-hi] [path]                    Display statistics for current directory or
                                   filesystem containing 'path'
exit                               Quit sftp
get [-P] remote-path [local-path]  Download file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln oldpath newpath                 Symlink remote file
lpwd                               Print local working directory
ls [-1aflnrSt] [path]              Display remote directory listing
lumask umask                       Set local umask to 'umask'
mkdir path                         Create remote directory
progress                           Toggle display of progress meter
put [-P] local-path [remote-path]  Upload file
pwd                                Display remote working directory
quit                               Quit sftp
rename oldpath newpath             Rename remote file
rm path                            Delete remote file
rmdir path                         Remove remote directory
symlink oldpath newpath            Symlink remote file
version                            Show SFTP version
!command                           Execute 'command' in local shell
!                                  Escape to local shell
?                                  Synonym for help
sftp>

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

Leave a Reply

Your email address will not be published. Required fields are marked *