How to check if there is a file in remote SFTP server before I copy and delete?

0

1

I am using standard SFTP in Linux and I want to check if there is a file in the file folder before I execute my script.

My script would only get the all the .TXT files in the file folder then would need to delete them after (since I can only copy but not cut files using SFTP)

This would be my script:

It copies all the .TXT files from drive E then save them into local/inbound folder:

#!/bin/bash
get /E:/*.TXT /local/inbound
rm /E:/*.TXT
bye

The reason I am asking is I do not want my remove file script to run when there is no file in the folder as there may be a case wherein between copy and delete, a file will be entered in the E: folder.

user1138281

Posted 2020-02-09T13:49:57.510

Reputation: 1

Answers

0

I'm not sure if I understand your question correct, but how about this:

scp ./test.txt usename@host:/tmp && rm ./test.txt

It copies the file test.txt and if the scp command succeeds then it removes the file.

OSC

Posted 2020-02-09T13:49:57.510

Reputation: 81