0

I have 10 files on remote server,I want to continuously check if there is any new file in the remote directory and if there is any new file it should be transferred to the local directory. I could write shell script to get the file but how do I get only the new files to be transferred,new files can be 1 to 10 in number Here is what i tried so far:

#!/bin/bash

user="abc"
ssh_host="host"
from_loc="/tmp/"
to_loc="/tmp/"
file="file.txt"

if ssh $ssh_host test -e $from_loc$file;
    then
        cd $to_loc
        sftp $user@$ssh_host <<EOF
cd $from_loc
get $file
bye
EOF
    else echo $file does not exist
fi

1 Answer 1

2

You can try rsync. It does what you want and more.

See this tutorial.

Sign up to request clarification or add additional context in comments.

2 Comments

actually i require only the differential files between remote and local directory to be copied to a separate directory in local server.
can rsync be used with .ppk file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.