How to SFTP send files created 1 minute ago, Linux?

apollowebdesigns :

How can I send files from a Linux machine to an sftp server that were created 1 minute ago?

I have tried using find, but I’m not sure how to pipe it through to sftp?

I have tried something like below

find | sftp {user}@{host}:{remote_dir} <<< $'put {local_file_path}'

But I don’t know how to pipe the files created one minute ago into the sftp command.

I cannot install additional packages as the Linux machine is not connected to the internet.

Sorin :

Assuming you don't have strange file names:

$ find -mmin -10 | sed 's/^/put /' | sftp -b - [email protected]
sftp> put ./16/test00116.gz
sftp> put ./20200113.gz
sftp> put ./log20200128.gz
  • -b - - read a batch file from stdin
  • sed 's/^/put /' - prefix each file with the put command.

A bit more robust, removing the uploaded file before trying to put the new one, and making sure sftp doesn't exit on error:

$ find -mmin -10 -exec basename -- "{}" \; -print | sed '1~2s/^/-rm /;0~2s/^/-put /' |  sftp -b - [email protected]
sftp> -rm exisingfile20200102.gz
sftp> -put ./2/existingfile20200102.gz
sftp> -rm newfile20200121.gz
Couldn't delete file: No such file or directory
sftp> -put ./21/newfile20200121.gz

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220284&siteId=1