-1

I want to get multiple files that were generated in last 1 day, from server to local. I'm using the following command which says "No such file or directory".

find username@server.xyz.com:/path-from-which-files-need-to-be-copied/ -type f -ctime -1 | xargs -ILIST scp LIST /Users/abcUser/Documents/test/

Error find: username@server.xyz.com:/path-from-which-files-need-to-be-copied/: No such file or directory

PS: I can access this location and scp from this location for single files with filenames.

Ron
  • 149
  • 2
  • 16
  • The `find` utility looks at a **local** filesystem. It's not able to reach across an ssh connection (if that's what you intended) and make a list of files on a remote server. You might want to look at `rsync` as a better solution for this. – ghoti Feb 11 '20 at 21:34
  • Thanks. Will look into it. – Ron Feb 11 '20 at 21:34
  • 1
    In the mean time, since this question is based on a false premise and isn't really about programming, you may wish to delete it just to keep the SO question queue a little cleaner. – ghoti Feb 11 '20 at 21:35
  • It is actually doable using find. My requirement specifically asks me for the last 1 days files. And i can't actually store all the files in local after processing. So rync won't work. Because rsync works only for the delta. – Ron Feb 12 '20 at 15:44

1 Answers1

1

find can find only local files. So run find on remote server, something along:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 |
xargs -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/

Note that xargs by default parses \ and quotes in it's own way. The best way to pass the result of find is to use zero terminated stream:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -print0 |
xargs -0 -ILIST scp username@server.xyz.com:LIST /Users/abcUser/Documents/test/   

But xargs will invoke separate scp session for each file, which will be very slow. So optimize it by running a single scp for all files, I think you could do it something like this:

ssh username@server.xyz.com find /path-from-which-files-need-to-be-copied/ -type f -ctime -1 -printf 'username@server.xyz.com:%p\\0' |
xargs -0 sh -c 'scp "$@" "$0"' /Users/abcUser/Documents/test/
KamilCuk
  • 120,984
  • 8
  • 59
  • 111