7

I often connect to a database by sftp protocol, and I get the data by doing get -r

is there any option to skip all existing file on my computer ? I tried get -r --overwrite but it does'nt work. (I know I could set my files in read only but I'ld like to find a better way).

p.deman
  • 255

3 Answers3

5

This is sort of possible with sftp. Use 'get -a -r'. According to the man page of sftp for ubuntu: http://manpages.ubuntu.com/manpages/artful/man1/sftp.1.html the -a option attempts to continue interrupted transfers and only overwrites a file if there are differences in the file.

Dante
  • 51
2

No, it is not possible. Manual page for sftp does not mention any option that would make that working. You would be best with copying the files to some known-to-be-empty location and then copy to your intended localtion with

get -r remote_path/ empty_path/
!cp --no-clobber empty_path/ real_target/
Jakuje
  • 6,605
  • 7
  • 30
  • 37
  • This is in fact possible with get -a. See Dante's answer and the sftp man page for caveats. – kontextify Feb 19 '21 at 11:40
  • @kontextify thank you for your interest in this question. The -a flag is really dumb and checks only the file size to continue interrupted downloads. If the local file is in place and has smaller size, it will try to append the rest of the remote file (probably corrupting the local file), if the file has large size, it will throw errors so I would not consider it a complete solution, but rather something that might work for some cases, but not for all ones. – Jakuje Feb 19 '21 at 15:36
  • Yes, it's good to read the man page and know these caveats! It's not exactly rsync. But for simple, non mission-critical syncing over a reliable network (my use case) this option is enough. – kontextify Feb 23 '21 at 16:58
2

I would suggest using rsync over ssh:

rsync -avz -e ssh --progress user@server:/var/db ~/db

Some further reading:

mgor
  • 1,211
  • 8
  • 13