简体   繁体   English

通过FTP命令或带有FTP命令的Shell脚本上传到Linux服务器后的TAR大小差异

[英]TAR size difference after uploading to Linux server via FTP command or a shell script with FTP command

I have a tar file "backup_20140626" with size 444477440. I uploaded it via FTP onto my NAS running with Linux like so: 我有一个tar文件“ backup_20140626”,大小为444477440。我通过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)

I downloaded the file and it could be opened. 我下载了文件,可以将其打开。

Then I wrote a script backup.sh to auotmate the uploading: 然后,我编写了一个脚本backup.sh来自动上传:

ftp -n 192.168.0.2 <<EOF
quote USER backup
quote PASS backup
cd /mnt/array1/_backup
put backup_20140626 
quit
EOF

OK, I ran the script: 好的,我运行了脚本:

#./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.

The transferred sizes of the same file are different! 同一文件的传输大小不同! I downloadeded the file again and it cannot be recognized as a tar file: 我再次下载了文件,但无法将其识别为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

Could somebody tell me what's wrong here? 有人可以告诉我这是怎么了吗? Thank you very much! 非常感谢你!

If you run dos2unix on your tar file, does it fix the file size? 如果在tar文件上运行dos2unix,它是否可以固定文件大小? If so, it's because it transferred as ASCII (not binary) regardless of what the program said. 如果是这样,那是因为无论程序说什么,它都以ASCII(不是二进制)格式传输。

You can specify 'binary' in your script, and if you didn't want to rewrite the script every time, you could also let it read the file name from an argument: 您可以在脚本中指定“二进制”,如果您不想每次都重写脚本,也可以让它从参数中读取文件名:

ftp -n 192.168.0.2 <<EOF
quote USER backup
quote PASS backup
binary
cd /mnt/array1/_backup
put backup_20140626
quit
EOF

Off topic, but if you didn't want to rewrite the script every time, you could have it read an argument from the command line ./ftpScript.sh backup_20140626 (or whatever the file is named that day). 脱离主题,但是如果您不想每次都重写脚本,则可以让它从命令行./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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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