我有一个大小为444477440的tar文件“backup_20140626”。我通过FTP将其上传到运行Linux的NAS上,如下所示:
>put backup_20140626
local: backup_20140626 remote: backup_20140626
229 Entering Extended Passive Mode (|||22735|)
150 Opening BINARY mode data connection for backup_20140626
100% |*************************************| 423 MB 26.59 MB/s 00:00 ETA
226 Transfer complete
444477440 bytes sent in 00:15 (26.57 MB/s)
我下载了文件,可以打开。
然后我写了一个脚本backup.sh来修改上传:
ftp -n 192.168.0.2 <<EOF
quote USER backup
quote PASS backup
cd /mnt/array1/_backup
put backup_20140626
quit
EOF
好的,我运行了脚本:
#./backup.sh
Connected to 192.168.0.2.
220 192.168.0.2 FTP server ready
331 Password required for backup
230 User backup logged in
250 CWD command successful
Local directory now /backup/dat
local: backup_20140626 remote: backup_20140626
229 Entering Extended Passive Mode (|||63859|)
150 Opening BINARY mode data connection for backup_20140626
100% |*************************************| 425 MB 21.42 MB/s --:-- ETA
226 Transfer complete
446076565 bytes sent in 00:19 (21.42 MB/s)
221 Goodbye.
同一文件的传输大小不同!我再次下载了该文件,它无法识别为tar文件:
#tar xvf backup_20140626
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
有人能告诉我这里有什么问题吗?非常感谢你!
答案 0 :(得分:0)
如果在tar文件上运行dos2unix,它是否修复了文件大小?如果是这样,那是因为无论程序说什么,它都以ASCII(非二进制)的形式传输。
您可以在脚本中指定'binary',如果您不想每次都重写脚本,也可以让它从参数中读取文件名:
ftp -n 192.168.0.2 <<EOF
quote USER backup
quote PASS backup
binary
cd /mnt/array1/_backup
put backup_20140626
quit
EOF
关闭主题,但如果您不想每次都重写脚本,可以让它从命令行读取一个参数 ./ ftpScript.sh backup_20140626 (或当天命名的文件)。
ftp -n 192.168.0.2 <<EOF
quote USER backup
quote PASS backup
binary
cd /mnt/array1/_backup
put $1
quit
EOF