在Linux系統中,你可以使用cron來設置定時任務。以下是如何在Linux FTP中設置定時任務的步驟:
打開終端。
輸入crontab -e命令來編輯當前用戶的crontab文件。如果你想為其他用戶設置定時任務,請使用sudo crontab -e -u username。
在打開的crontab文件中,你可以按照以下格式添加定時任務:
* * * * * command-to-be-executed
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
lftp。首先確保你已經安裝了lftp。如果沒有,請使用以下命令安裝:對于基于Debian的系統(如Ubuntu):
sudo apt-get install lftp
對于基于RPM的系統(如Fedora、CentOS):
sudo yum install lftp
lftp命令。例如,如果你想每天凌晨1點連接到FTP服務器并下載一個文件,你可以添加以下行:0 1 * * * lftp -e 'open ftp://username:password@ftp.example.com; get /path/to/remote/file /path/to/local/file; quit' -u username,password
請將username、password、ftp.example.com、/path/to/remote/file和/path/to/local/file替換為實際的值。
crontab -l命令查看當前用戶的定時任務列表。注意:在crontab文件中存儲密碼可能會導致安全風險。作為替代方案,你可以考慮使用.netrc文件或在命令中使用環境變量來存儲FTP憑據。