在BASH脚本中上传FTP

我需要将目录/ home / test的全部内容上传到我的ftp服务器,在特定的文件夹中。 然后,我将通过cron每小时安排脚本。 任何例子?

NB。 考虑到我在一个Netgear的ReadyNAS Duo(一个debian盒),我不能安装lftp或相似的,只有标准的命令:)

在网上find这个有质量文档的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 

configuration和保存.sh脚本后,使其可执行:

chmod + x ftpscript.sh

最后,configuration你的cronjob

命令在一行中:

 ftp -in -u ftp://username:password@servername/path/to/ localfile 

curl能够上传文件到FTP服务器。

 curl -T "$FILE(s)" -u $USERNAME:$PASSWORD $SERVER/$DIR/ 

你也可以使用$FILE的glob模式。

如果你有'curl',这是相当标准的,它可以做无人看pipe的FTP上传(请参阅手册页的-T选项)

如果ssh安装并configuration为允许文件传输,则可以使用scp

如果不是netcatrsync可能是一个选项。

如果你能够安装或编译程序,一个名为ftpsync的工具可能就是你正在寻找的东西。 [我从来没有尝试过,似乎有几个公用事业要么称为或非常相似。]

在一个bash脚本中,你应该可以做如下的事情:

  #!/bin/bash echo " verbose open 1.2.3.4 USER ftpuser ftppasswd put /path/to/stuff.tar.gz bye " > ftp -n > ftp_$$.log 

把你的目录放在第一位将是一个好主意,并使之简单得多。 此外,根据您的目录大小和networking的速度,您可能需要考虑做差分焦点。