简体   繁体   English

bash + ftp:上传文件为空

[英]bash + ftp: File is empty on upload

I have written a bash script to update a page on my company's website. 我已经编写了一个bash脚本来更新公司网站上的页面。 Here's what I've got so far: 到目前为止,这是我得到的:

#!/bin/bash

ruby final_07.rb

HOST=ftp.website.com
USER=username
PASSWD=password

ftp -n -v $HOST <<EOF
user $USER $PASSWD
delete warehouse.html.old
rename warehouse.html warehouse.html.old
put warehouse.html warehouse.html

EOF

It runs the Ruby script just fine. 它可以很好地运行Ruby脚本。 It connects to the FTP just fine. 它可以很好地连接到FTP。 It even renames the old file just fine. 它甚至可以重命名旧文件。 However, when it "uploads", I just get a file named 'warehouse.html' that is 0 bytes - it's totally empty. 但是,当它“上载”时,我只是得到一个名为“ warehouse.html”的文件,该文件为0字节-完全为空。 I checked, and the source file is fine. 我检查了,源文件很好。 When I manually upload with FileZilla, it works just fine, too. 当我使用FileZilla手动上传时,它也可以正常工作。 So, what gives? 那么,有什么用呢?

Here's the log from my terminal window: 这是我的终端窗口中的日志:

john@starfire:~/code/ruby/idealm_db_parser/final$ ./update_script_02.sh
Connected to www.website.com.
220 FTP Service
Remote system type is UNIX.
Using binary mode to transfer files.
331 Password required for user.
230 User user logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
250 DELE command successful
350 File or directory exists, ready for destination name.
250 Rename successful
local: warehouse.html remote: warehouse.html
200 PORT command successful
150 Opening BINARY mode data connection for warehouse.html
226 Transfer complete.
221 

Thanks in advance for any help. 在此先感谢您的帮助。 I'm running Ubuntu 10.10, if that helps. 我正在运行Ubuntu 10.10,如果有帮助的话。

You could try to 您可以尝试

  • switch to asci mode before you put your file 放入文件之前切换到asci模式
  • use passive ftp mode for transfering the file 使用被动ftp模式传输文件

I think I got it sorted. 我想我把它整理好了。 I removed the lines: 我删除了以下行:

delete warehouse.html.old
rename warehouse.html warehouse.html.old

and that seemed to do the trick. 这似乎可以解决问题。 For some reason, apparently the script was zeroing the warehouse.html file on MY computer, then uploading that. 由于某种原因,该脚本显然将我的计算机上的Warehouse.html文件清零,然后上传了该文件。

Thanks to everyone who helped, though. 感谢所有帮助的人。

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

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