使用lftp 将本地文件夹与ftp 文件夹同步的语法?
我想彼此同步两个文件夹。它应该有两种方式,始终保持文件夹最新(我使用常规的 cronjob)。但是,首先我无法实现双向文件传输(它只是从 ftp 下载,而不是相反)。
其次,它从 ftp 下载全部内容,尽管登录信息已在 ftp 上设置,因此访问仅限于特定文件夹。为什么??
这是代码(提前致谢!):
#!/bin/bash
#get username and password
USER=username
PASS=password
HOST="myftpserver.com/users/user1/" #here I have tried with only specifying server name as well as including whole path
LCD="~/Desktop/localfolder/"
RCD="users/user1/"
lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
mirror -c --reverse --verbose $LCD $RCD" #I have tried a few different options w/o result
I would like to synchronize two folders with each other. It should go two ways, always keeping the folders up to date (I use a regular cronjob). However, first I do not get the two way file transfer to work (it just downloads from the ftp and not the opposite).
Secondly, it downloads the whole content from the ftp, even though the login information has been set up on the ftp so that access is only restricted to a specific folder. Why??
Here is the code (thanks in advance!):
#!/bin/bash
#get username and password
USER=username
PASS=password
HOST="myftpserver.com/users/user1/" #here I have tried with only specifying server name as well as including whole path
LCD="~/Desktop/localfolder/"
RCD="users/user1/"
lftp -c "set ftp:list-options -a;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
mirror -c --reverse --verbose $LCD $RCD" #I have tried a few different options w/o result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可能不再需要这个了(晚了四年),但我会更新这个,如果有人遇到同样的问题,这里会提供帮助。
本地目录到 FTP 服务器目录
如果要将 FTP 服务器文件夹与文件夹中的内容同步,您应该使用类似此
FTP 服务器目录到本地目录的内容
只需删除 --reverse 并交换镜像命令中的文件夹即可。
要执行像您在问题中评论的那样的操作,同步两种方式并保留每种方式的最新值,我不认为单独使用 lftp 是可能的,您需要一些东西来检测更改并决定使用哪个脚本。
You probably don't need this anymore (4 years late) but I'll just update this, and if someone get's here with the same issue here's a help.
Local directory to FTP server directory
If you want to sync the FTP server folder with the content in your folder you should use something like this
FTP server directory to your local directory
Simply remove the --reverse and swap the folders in the mirror command.
To do something like you commented in the question, sync both ways and keep the most updated value from each, i don't believe it's possible using lftp alone you'll need something to detect the change and decide which script use.
如果将远程FTP服务器文件夹同步到本地文件夹并使用上面的lftp-4.9,请尝试以下脚本:
if sync the remote FTP server folder to the local folder and using lftp-4.9 above, please try this script: