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>