2015-08-20 210 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