【问题标题】:Bash script to upload file by FTP通过 FTP 上传文件的 Bash 脚本
【发布时间】:2015-08-20 16:00:49
【问题描述】:

我正在尝试使用此脚本创建文件并将其上传到 ftp 服务器。该脚本基于论坛中的其他一些脚本。

    HOST=example.com #This is the FTP servers host or IP address.
    USER=ftpuser #This is the FTP user that has access to the server.
    PASS=1234 #This is the password for the FTP user.
    FILE_PREFIX=FRAME

    timestamp() {
      date +"%s"
    }

    ftp() {
        ftp -i -n $HOST << END_SCRIPT
        user $USER $PASS
        # #cd /path/to/file
        put $FILENAME
        bye

    END_SCRIPT
    }

    # # Call 1. Uses the ftp command with the -inv switches. 
    # #-i turns off interactive prompting. 
    # #-n Restrains FTP from attempting the auto-login feature. 
    # #-v enables verbose and progress. 


    # shoot picture

    while true; do
        FILENAME=${FILE_PREFIX}_$(timestamp).txt
        echo $FILENAME > $FILENAME

        echo "Subiendo $FILENAME"
        ftp

        sleep 2
    done
    EOF

当我执行脚本时,我收到以下错误消息:

script.sh: 14: script.sh: 0: 打开的文件太多

你能帮我解决这个错误吗? 谢谢

【问题讨论】:

    标签: bash ftp


    【解决方案1】:

    将您的函数 ftp 重命名为其他名称,并将它的调用重命名为 sleep 2

    【讨论】:

    • 谢谢,这有效(我必须等待 3 分钟才能接受回复)。现在我有一个新的问题,也许我必须开始一个新的问题,但不会在这里尝试:一旦打开 ftp 连接,我会在屏幕中收到此消息:?Invalid command
    • 请开始一个新问题。切换到Super User 会很有用。