Ubuntu – How to use find in scp command

findscpssh

I would like to use scp command fo transfer some files from remote server to local machine. The problem I have is to find the files and then direct them to scp command. I don't want to generate an ssh-key on the server, so I have to use the command from the local machine to perform the task.

Actually, I need something like below:

scp username@server_IP:/path/to/file/`find . -ctime -1 -type f` ./

The problem is that find command does not work.

Please advice.

Best Answer

  • Create a local target directory

    mkdir /path/to/targetdir
    
  • Identify the remote source directory /path/to/sourcedir

  • Run the following one-liner (edited with the correct source and target directories and user@ip-address for the server),

    ssh username@ip-adress '(cd /path/to/sourcedir; find . -print | cpio -oBav -Hcrc)' | ( cd /path/to/targetdir && cpio -ivumd )