Site icon Bytefreaks.net

Using scp to copy a folder on a custom port

Advertisements
while true;
do
date;
scp -rp -P 2222 $SOURCE_DIRECTORY $REMOTE_USER@$REMOTE_SERVER:$DESTINATION_DIRECTORY;
sleep 60;
done;

The above code was used to copy the contents of a local folder to a remote one every one minute. We did not want to lose the metadata of the files (including the modification date of the files) so we used the -p parameter to preserve that information.

The -P 2222 parameter instructs scp to use a different port rather the default.

The -r is used to instruct the copy to get all contents of the folder and its sub-folders.

The above code as a one-liner is:

while true; do date; scp -rp -P 2222 $SOURCE_DIRECTORY $REMOTE_USER@$REMOTE_SERVER:$DESTINATION_DIRECTORY; sleep 60; done;

This post is also available in: Αγγλικα

Exit mobile version