In this chapter, we’ll explore file transfer tools that allow you to move files between systems efficiently and securely. You’ll learn how to use tools like scp, rsync, lftp, and ncftp to copy files, synchronize directories, and manage remote file transfers. By the end of this chapter, you’ll be able to transfer files like a pro.
File transfer is a common task in system administration, development, and data management. Whether you’re backing up data, deploying software, or sharing files, these tools make the process fast, reliable, and secure.
scpscp (Secure Copy) is a command-line tool for securely copying files between local and remote systems using SSH.
$ scp file.txt user@remote_host:/path/to/destination/$ scp user@remote_host:/path/to/file.txt /local/destination/$ scp -r directory/ user@remote_host:/path/to/destination/Copy a file to a remote server:
$ scp report.pdf amar@192.168.1.100:/home/amar/documents/rsyncrsync is a powerful tool for synchronizing files and directories between systems. It’s efficient because it only transfers changes.
$ rsync -avz /local/directory/ user@remote_host:/remote/directory/-a: Archive mode (preserves permissions, timestamps, etc.).-v: Verbose output.-z: Compress data during transfer.
Sync from a remote host to local:$ rsync -avz user@remote_host:/remote/directory/ /local/directory/
Dry run (simulate the sync):$ rsync -avz --dry-run /local/directory/ user@remote_host:/remote/directory/
Sync a local directory to a remote server:
$ rsync -avz ~/projects/ amar@192.168.1.100:/backup/projects/lftp for Advanced File Transferslftp is a sophisticated FTP client that supports multiple protocols (FTP, HTTP, SFTP, etc.) and advanced features like parallel transfers and scripting.
$ lftp ftp://user:password@ftp.example.com$ lftp -e "get file.txt; quit" ftp://user:password@ftp.example.com$ lftp -e "mirror /remote/directory/ /local/directory/; quit" ftp://user:password@ftp.example.comDownload a file from an FTP server:
$ lftp -e "get report.pdf; quit" ftp://user:password@ftp.example.comncftp for User-Friendly FTP Transfersncftp is a user-friendly FTP client with features like bookmarking and recursive directory downloads.
bash ncftp ftp.example.combash get file.txtbash get -R directory/Download a file from an FTP server:
$ ncftp ftp.example.com
$ get report.pdf
$ quitUse rsync to back up a local directory to a remote server:
$ rsync -avz ~/documents/ amar@192.168.1.100:/backup/documents/Use lftp to download a file:
$ lftp -e "get file.txt; quit" ftp://$ user:password@ftp.example.comUse rsync to sync a remote directory to your local machine:
$ rsync -avz amar@192.168.1.100:/remote/projects/ ~/local/projects/For efficient file transfers across multiple devices and cloud services, rclone supports various cloud storage systems, allowing you to sync or copy files as if dealing with a local filesystem.
Syncthing enables secure, peer-to-peer file synchronization between personal machines. For large file transfers over unreliable connections, rsync and wget’s –continue option ensure resumable transfers, minimizing wasted bandwidth and time. These modern approaches are essential for managing files across different systems and cloud providers.
$ rclone copy /local/path remote:path
$ rsync --partial /source/ /destination/curl$ curl https://example.com$ curl -O https://example.com/file.zip$ curl -d "param1=value1¶m2=value2" -X POST https://example.com$ curl -L https://example.comwget$ wget https://example.com/file.zip$ wget --mirror https://example.com$ wget -c https://example.com/file.zipIn this chapter, we’ll explore command-line tools for web browsing, email, and network diagnostics. These tools allow you to interact with the web, manage emails, and troubleshoot network issues directly from the terminal. By the end of this chapter, you’ll be able to efficiently perform network-related tasks using powerful command-line utilities.
The command line is not just for system administration—it’s also a powerful platform for interacting with networks. Whether you’re downloading files, sending emails, or diagnosing network issues, these tools will help you get the job done quickly and efficiently.
2. Web Browsing Toolslynx
$ lynx https://example.com/ and type your search term.Enter to follow them.muttbash $ sudo apt install mutt # Debian/Ubuntu $ sudo dnf install mutt # Red Hat/Fedoramutt: bash $ muttm to compose a new email.y to send.Enter to read.mailbash $ sudo apt install mailutils # Debian/Ubuntu $ sudo dnf install mailx # Red Hat/Fedorabash $ echo "Hello" | mail -s "Subject" user@example.combash $ mailmail interface, type d followed by the email number.
By mastering these network tools, you can: - Browse the web and download files using curl, wget, and lynx. - Send and receive emails using mutt and mail. - Diagnose network issues using ping, traceroute, and netstat. - Securely connect to remote servers using ssh.
Let’s put your new skills to the test:
1. Use scp to copy a file to a remote server.
2. Use rsync to synchronize a local directory with a remote backup.
3. Use lftp to download a file from an FTP server.
4. Use ncftp to explore an FTP server and download a directory.
5. Fetch a Webpage: - Use curl to fetch the content of a webpage.
6. Download a File: - Use wget to download a file from the web.
7. Send an Email: - Use the mail command to send an email.
That’s it for Chapter 21! You’ve now learned how to use file transfer tools like scp, rsync, lftp, and ncftpto move files between systems efficiently and securely. In the next chapter, we’ll dive into Linux security basics—how to secure your system using SSH, firewalls, and encryption. Until then, practice transferring files to become more comfortable with these tools.