2015-08-20 174 views
0

我试图使用这个脚本创建并上传文件到FTP服务器。该脚本基于这里在论坛中看到的其他脚本。Bash脚本通过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:打开的文件太多

你能帮助我解决错误? 谢谢

回答

0

将您的功能ftp重命名为其他东西,然后再调用sleep 2

+0

谢谢,这工作(我必须等待3分钟接受回应)。现在我有一个新的问题*,也许我必须开始一个新的问题,但不会尝试在这里:一旦打开了ftp连接,我在屏幕上看到这条消息:*?无效的命令* –

+1

请开始一个新问题。切换到[超级用户](http://superuser.com/tour)可能很有用。 – Cyrus