Moving Files Remotely
Just as ssh secures the shell, scp and sftp secure file transfers.
scp (Secure Copy)
scp copies files between hosts on a network, using the SSH protocol for data transfer and authentication.
1. Copying a local file TO a remote machine:
bash
Copy report.txt to the remote user's home directory (~) on the server
$ scp report.txt user@server_ip:~
2. Copying a file FROM a remote machine to local:
bash
Copy log file from remote server to the current local directory (.)
$ scp user@server_ip:/var/log/syslog .
3. Recursive Copy (-r): Required for directories.
bash $ scp -r local_dir user@server_ip:/backup/
sftp (Secure File Transfer Protocol)
sftp provides an interactive command-line environment similar to FTP, but secured by SSH. It is useful for managing multiple files or navigating the remote filesystem before transfer.