我一直在尝试压缩一个文件,然后使用 bash 脚本通过 FTP 上传它,但它上传的是一个损坏的 zip 文件。我环顾四周,正在尝试使用 lsof | grep 以确认文件是否完整,但我不确定自己在做什么。
所以我有
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
并且 test.zip 在上传时已损坏,因此在另一台服务器上无法读取,但在服务器上压缩后,我检查时一切正常。
感谢任何类型的建议,我对这类事情还很陌生,并试图在堆中搜索以找到解决方案,但不太确定我的方向是否正确。提前致谢。
最佳答案
来自手册页:
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.
我想问题是您没有以二进制模式传输文件。
试试这个:
ftp -n <<EOF
open myserver
user user pass
binary
put test.zip
EOF
关于bash - 等到 zip 完全写入然后继续,Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27239184/