Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Send files with sftp then delete afterwards one line?

Writer Sophia Terry

How can I send files using sftp then delete them afterwards?

I have managed to get this far with sending all files with a set extension from a directory,

sftp user@remote <<< $'put -r /path/to/file/test_file/*.json'

but how can I delete them once I have sent them and only if they have been successfully sent on the one line command?

Also, the server I am using is very locked down, so I won't be able to install additional software from the internet and could this be kept as a one line send. This will also be used with cron, hence using one line.

1 Answer

If you need it in one line, use && operator:

sftp user@remote <<< $'put -r /path/to/file/test_file/*.json' && rm /path/to/file/test_file/*.json

It will execute rm only if sftp has succeeded. Adding -b - to sftp is probably a good idea (if not necessary).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy