Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait until zip fully written then continue, Bash Script

I've been trying to zip a file and then upload it by FTP using a bash script, but it's uploading a corrupt zip file. I've had a look around and I'm trying to use lsof | grep to confirm the file is complete but I'm not really sure what I'm doing.

So I've got

cd /var/test/tobezipped
zip -r test.zip *
FOLDER="/var/test/tobezipped"
ZIPS=$(ls $FOLDER)
for F in $zips ; do
  while [ -n "$(lsof | grep $F" ] ; do
  sleep 1
done
ftp -n <<EOF
open myserver
user user pass
put test.zip
EOF
done

and test.zip is corrupt at the time it's being uploaded, so on the other server it's not readable but on the server it's zipped on it's all good by the time I check it.

Any kind of advice is appreciated, I'm pretty new to this sort of thing and tried to search around heaps to find a solution, not too sure I'm going in the right direction. Thanks in advance.

like image 567
Justin Avatar asked Jul 13 '26 03:07

Justin


1 Answers

From the man page:

put local-file [remote-file] Store a local file on the remote machine. If remote-file is left unspecified, the local file name is used after processing according to any ntrans or nmap settings in naming the remote file. File transfer uses the current settings for type, format, mode, and structure.

I guess the problem is that you are not transfering files in BINARY mode.

Try this:

ftp -n <<EOF
open myserver
user user pass
binary
put test.zip
EOF
like image 71
user987339 Avatar answered Jul 14 '26 22:07

user987339



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!