Jump to content

How to securely move/transfer files between Linux environments


FunkyBuddha

Recommended Posts

Posted

You can use rsync to move your data across two Linux machines.

Command:

  • rsync -r --remove-source-files -P -e ssh remoteuser@remotehost:/remote/path /local/path

Parameters explained:

  • -r (recurse into directories)
  • --remove-source-files (delete source file once copied -- note: this will not delete directories)
  • -P (keep partially transferred files -- useful when copy is interrupted. it will be able to restart using the partial file)
  • -e (specifies the remote shell to use -- in our example, ssh is specified)

This command pulls data from the remote machine. You will need to execute this on the target local machine.

  • Thanks 2
Posted

Here's a bash script you can use to run the process in the background.

Requirement(s):

  • Uses sshpass to automate password input for ssh

Bash:

Quote

#!/bin/bash -x

rmt_user=remote_user_id
rmt_host=ip_address_of_remote_host
rmt_dir=/path/to/folder
local_dir=/path/to/folder

sshpass -p $(cat ~/.password) rsync -r --remove-source-files --progress -p -e ssh $rmt_user@$rmt_host:$rmt_dir $local_dir

 

  • Thanks 1

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...