bash - 等到 zip 完全写入然后继续,Bash 脚本

标签 bash ftp zip corrupt

我一直在尝试压缩一个文件,然后使用 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/

相关文章:

linux - 将文件重命名为 md5 sum + 扩展名 (BASH)

c# - 在 TLS : The remote server return an error : 234 AUTH TLS OK 上使用 FtpWebRequest 的问题

linux - 如何在我的用户名中使用带有 @ 符号的 linux 命令行 ftp?

javascript - 使用内置模块压缩文件夹

java - 如何将大 zip 文件分解为更小的 zip 文件?

deployment - 是否有支持现代多线程归档程序的任务 - 7zip、winrar 等?

bash - 想要通过将命令的输出重定向到变量来检查命令是否成功

linux - bash 循环限制

php - 需要从日志中读取数据...tail、grep 和 inotifywait

scripting - WinSCP 命令行被动模式