Practice Exercise: Transferring Files
Objectives
- Learn how to transfer files between systems using various methods.
- Understand the differences between tools like
scp
,rsync
, andftp
.
Scenario
As a Linux enthusiast, you'll often need to transfer files between different systems, whether they are remote servers, your local machine, or even other users' computers. This exercise will help you become proficient in using tools like scp
, rsync
, and ftp
for file transfers.
Tasks
Task 1: Transferring Files with scp
- Open a terminal on your local machine.
- Use
scp
to copy a file from your local machine to a remote server. For example:scp file.txt user@remote-server:/path/to/destination
. - Observe the file transfer process and ensure it reaches the remote server.
[intern@intern-a1t-inf-lnx1 ~]$ scp intern@192.168.64.2:/home/projects/my_history projects my_history 100% 68 57.7KB/s 00:00
Task 2: Transferring Files with rsync
- In the terminal, use
rsync
to synchronize a directory from your local machine to a remote server. For example:rsync -avz /local/directory/ user@remote-server:/path/to/destination/
. - Verify that the contents of the local directory are synchronized with the remote server.
[intern@intern-a1t-inf-lnx1 ~]$ rsync -avz intern@192.168.64.2:/home/projects/ projects/ receiving file list ... done ./ myscript.sh project_plan.txt sent 66 bytes received 338 bytes 808.00 bytes/sec total size is 136 speedup is 0.34 [intern@intern-a1t-inf-lnx1 ~]$ ls projects my_history myscript.sh project_plan.txt
Task 3: Transferring Files with ftp
- Open a terminal on a different machine.
- Use an FTP client like
ftp
orlftp
to connect to the FTP server. For example:ftp ftp://user@remote-server
. - Upload and download files to and from the FTP server.
- Using
lftp
I can now access the filesystem of the remote server[intern@intern-a1t-inf-lnx1 ~]$ lftp intern@192.168.64.2 Password: lftp intern@192.168.64.2:~> lftp intern@192.168.64.2:~> ls /home/projects/ -rw------- 1 1000 1000 68 Sep 20 10:54 my_history -rwsrwxr-x 1 1000 1000 68 Sep 19 12:42 myscript.sh -rw-rw-r-- 1 1000 1000 0 Sep 19 09:28 project_plan.txt lftp intern@192.168.64.2:~> bye
Task 4: Secure File Transfer with sftp
- Use
sftp
(SSH File Transfer Protocol) to securely transfer files between your local machine and a remote server. For example:sftp user@remote-server
. - Upload and download files securely using
sftp
.[intern@intern-a1t-inf-lnx1 ~]$ sftp intern@192.168.64.2 sftp> ls /home/projects /home/projects/my_history /home/projects/myscript.sh /home/projects/project_plan.txt
Conclusion
By completing these exercises, you've gained practical experience in transferring files between systems using tools like scp
, rsync
, ftp
, and sftp
. These tools are essential for managing files across different machines in a Linux environment.