6 How do you copy to and from the remote computer?
6.1 How Do You Copy To and From the Remote Computer?
Copying files to and from a remote computer is a common task when working with servers or collaborating with others over a network. In Bash, you can use several tools to accomplish this, with scp (secure copy) and rsync being the most commonly used commands.
6.1.1 Using scp (Secure Copy)
The scp command allows you to securely transfer files between your local machine and a remote machine using SSH (Secure Shell). It can also be used to transfer files between two remote machines.
6.1.1.1 Copying a File from Local to Remote
scp localfile.txt username@remotehost:/path/to/remote/directory- localfile.txt: The file you want to copy from your local machine.
- username: Your username on the remote machine.
- remotehost: The IP address or hostname of the remote machine.
- /path/to/remote/directory: The directory on the remote machine where you want to copy the file.
6.1.1.2 Example:
scp howToCopy.txt s-99@192.1xx.xxx.xxx:/mnt/s-ws/s-99/thesis6.1.1.3 Copying a File from Remote to Local
scp username@remotehost:/path/to/remotefile.txt /path/to/local/directory- /path/to/remotefile.txt: The file you want to copy from the remote machine.
- /path/to/local/directory: The directory on your local machine where you want to save the file.
6.1.1.4 Example:
scp s-99@192.1xx.xxx.xxx:/mnt/s-ws/s-99/thesis/my_draft.txt .6.1.2 Using rsync
The rsync command is a powerful tool for copying and synchronizing files and directories between two locations over a network. It is more efficient than scp for large data transfers or regular backups because it only copies the differences between the source and the destination.
6.1.2.1 Basic rsync Command
rsync /path/to/local/directory/ username@remotehost:/path/to/remote/directory/6.1.2.2 Example:
Copying a directory from local to remote:
rsync howToCipy.txt mamun@146.1xx.xx.xx:/mnt/s-ws/mamun/thesis/Copying files and directory from remote to local:
rsync mamun@146.1xx.xx.xx:/mnt/s-ws/mamun/thesis/my_draft.txt .
rsync mamun@146.1xx.xx.xx:/mnt/s-ws/mamun/thesis .6.1.3 Summary
scp: Simple and straightforward for copying files between local and remote machines. Best for one-time transfers.rsync: More efficient and powerful for synchronizing files and directories, especially useful for regular backups and large data sets.
Both scp and rsync rely on SSH for secure data transfer, ensuring that your files are copied safely over the network. Choose the tool that best fits your needs based on the complexity and frequency of your file transfer tasks.