Transferring Files Between Linux Servers via Command Line with Resumable Transfer

Transferring files between Linux servers via the command line can be accomplished efficiently using tools like rsync or scp. However, ensuring that the transfer can resume from where it left off in case of a connection drop requires additional considerations. In this article, we'll explore how to transfer files securely between servers while enabling resumable transfer capabilities.

1. Using rsync:

rsync is a powerful tool for synchronizing files and directories between two locations. It's widely used for efficient file transfers and supports resuming partially transferred files.

Syntax:

rsync [options] source destination

Example:

rsync -avP --partial source-file user@destination:/path/to/destination
  • -avP: This combination of options stands for archive mode (preserves permissions, timestamps, etc.), verbose output, and progress display.
  • --partial: This option allows rsync to keep partially transferred files in case of interruptions.

2. Using scp:

scp (secure copy) is another commonly used tool for transferring files securely between servers over SSH.

Syntax:

scp [options] source user@destination:/path/to/destination

Example:

scp -P 22 -r source-folder user@destination:/path/to/destination
  • -P 22: Specifies the port to connect to on the remote host. The default port for SSH is 22.
  • -r: Recursively copy entire directories.

3. Resuming Transfer:

Both rsync and scp automatically attempt to resume transfers if the connection is interrupted. However, if you want to ensure resumability explicitly, you can use the --partial option with rsync or the -o option with scp.

Example (rsync):

rsync -avP --partial source-file user@destination:/path/to/destination

Example (scp):

scp -o "ControlMaster auto" -o "ControlPath ~/.ssh/%h-%r" -o "ControlPersist 10m" source-file user@destination:/path/to/destination
  • -o "ControlMaster auto": Enables the SSH control master feature, which allows multiple sessions over a single connection.
  • -o "ControlPath ~/.ssh/%h-%r": Specifies the location and format for the control socket file.
  • -o "ControlPersist 10m": Sets the duration for which the control master connection should persist after the last session is closed.

4. Monitoring Transfer Progress:

Both rsync and scp provide progress indicators by default. However, you can enhance this by using the -v (verbose) option with rsync or -P (progress) with scp.

Conclusion:

Transferring files between Linux servers via the command line is a straightforward process using tools like rsync and scp. By utilizing their resumable transfer capabilities, you can ensure that file transfers can resume seamlessly from where they left off in case of connection interruptions. This ensures efficient and reliable file transfers between servers.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Best Practices to Harden a Linux Server

Securing a Linux server is essential to protect it from potential threats and vulnerabilities....

Powered by WHMCompleteSolution