简体   繁体   中英

shell script: ftp to check existing file

I've a simple shell script to transfer daily log file to another Windows FTP.

The problem is if the file is already there, it will still uploading a new one even though the file name is exactly the same.

How to perform a quick check on this script? If the file is there, then it won't proceed with FTP transfer

ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
mput $FILE
bye
EOT

It is easy in Unix with ftp . First login to the system through ftp and run a ls -ltr command through ftp and list the files in a history.txt file(see below my example) and while transferring the file first check whether that file is already available in history file or not. And if available do not transfer that file. I do it like below:-

HISTORY_FILE="history.txt"

ftp -n -v $HOST << EOT
user $USER $PASSWD
prompt
bin
ls -rtE $HISTORY_FILE
bye
EOT

Now you can use below command to check:-

ISFILENAMEEXIST=$(cat $HISTORY_FILE | grep $FILE)

Now if the file exist in history.txt , do not send that file and if not available send it through ftp .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM