I am very new to sftp but here is what I'd like to achieve:

In a remote folder main I have three subdirectories: sub1, sub2 sub3. My local machine also has a main folder with the three subdirectories. I would like to loop over the three subdirectories, find newly created files, and place them in the corresponding local subdirectories.

It's ok if I just need to call the same command three times, one per directory, if there's no way to create a loop.

When I say I'd like to only get the new files, I'd ideally want to compare the creation/modification date of the files in my remote directory to the local equivalents (if they exist). For example, for a new file file1.csv in sub1 on my remote machine, I'd like to see if there is a file1.csv in sub1 on my local machine. If so, compare the dates, and if the remote one is more recent, send it to my local folder. If the file doesn't exist, directly send it to the local folder.

If this cannot be achieved, I could settle for a system that only sends files created "today" to my local folder.

What's the best way to accomplish this?

Thank you for your help!


1 Answer 1


If I am reading this right you need to get the new or changed files from the remote dirs to the local dirs.

Not sure if there is a reason you specifically want or need to use sftp ?

If you are open to alternatives, have you considered rsync ?

Plenty of online tutorials and documentation for rsync.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .