我需要将目录 /home/test 的全部内容上传到我的 ftp 服务器的特定文件夹中。 然后我将通过 cron 每小时安排一次脚本。有什么例子吗?
注意。考虑到我使用的是 Netgear ReadyNAS Duo(一个 debian 机器)并且我无法安装 lftp 或类似软件,只能安装标准命令 :)
小智 12
在网上找到了这个有质量文档的 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
Run Code Online (Sandbox Code Playgroud)
配置并保存 .sh 脚本后,使其可执行:
chmod +x ftpscript.sh
最后,配置您的 cronjob
小智 8
一行命令:
ftp -in -u ftp://username:password@servername/path/to/ localfile
Run Code Online (Sandbox Code Playgroud)
小智 7
curl
能够将文件上传到 FTP 服务器。
curl -T "$FILE(s)" -u $USERNAME:$PASSWORD $SERVER/$DIR/
Run Code Online (Sandbox Code Playgroud)
您还可以将 glob 模式用于$FILE
.