简体   繁体   中英

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:

>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:

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 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? If so, it's because it transferred as ASCII (not binary) regardless of what the program said.

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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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