Bash脚本通过FTP上传文件

时间:2015-08-20 16:00:49

标签: bash ftp

我尝试使用此脚本创建文件并将其上传到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:打开的文件太多

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

1 个答案:

答案 0 :(得分:0)

在与ftp对齐之前,将您的函数sleep 2重命名为其他内容及其调用。