Bash

BASH 腳本中的 FTP 上傳

  • December 17, 2015

我需要將目錄 /home/test 的全部內容上傳到我的 ftp 伺服器的特定文件夾中。 然後我將通過 cron 每小時安排一次腳本。有什麼例子嗎?

注意。考慮到我在 Netgear ReadyNAS Duo(一個 debian 盒子)上,我不能安裝 lftp 或類似的東西,只能安裝標準命令 :)

在網上找到了這個具有高質量文件的 bash 腳本:

#!/bin/bash

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

# 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. 

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS

# Call 3. Here you will change to the directory where you want to put or get
cd /path/to/file

# Call4.  Here you will tell FTP to put or get the file.
put test.txt

# End FTP Connection
bye

EOF

配置並保存 .sh 腳本後,使其可執行:

chmod +x ftpscript.sh

最後,配置你的 cronjob

引用自:https://serverfault.com/questions/279176