Transferring files via SSH can be done using SCP (Secure Copy) and SFTP (SSH File Transfer Protocol).
Copy a File to Remote Host:
Use SCP to copy a file from localhost to a remote host.
scp ./test.txt cent@node01.emc.world:~/
Copy a File from Remote Host:
To copy a file from a remote host to the localhost:
scp cent@node01.emc.world:/home/cent/test.txt ./test.txt
Subsystem sftp /usr/libexec/openssh/sftp-server in /etc/ssh/sshd_config.Start SFTP Session:
Connect to a remote host using SFTP:
sftp cent@node01.emc.world
Navigating and Managing Files:
Use various SFTP commands to navigate and manage files.
pwd # Show current directory on remote host
!pwd # Show current directory on localhost
ls -l # Show files in current directory on remote host
!ls -l # Show files in current directory on localhost
cd public_html # Change directory on remote host
put test.txt # Upload a file to remote host
get test.txt # Download a file from remote host
mkdir testdir # Create a directory on remote host
rmdir testdir # Delete a directory on remote host
rm test2.txt # Delete a file on remote host
!command # Execute local shell commands
quit # Exit SFTP session
For example:
sftp> pwd
sftp> !pwd
sftp> ls -l
sftp> !ls -l
sftp> cd public_html
sftp> put test.txt redhat.txt
sftp> get test.txt
sftp> mkdir testdir
sftp> rmdir testdir
sftp> rm test2.txt
sftp> !cat /etc/passwd
sftp> quit