使用lftp将本地文件夹与ftp文件夹同步的语法? [英] Syntax for using lftp to synchronize local folder with an ftp folder?

查看:851
本文介绍了使用lftp将本地文件夹与ftp文件夹同步的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同步两个文件夹。它应该有两种方式,始终保持文件夹是最新的(我使用常规的cronjob)。然而,首先我没有得到双向文件传输的工作(它只是从ftp下载,而不是相反)。其次,它将整个内容从即使已经在ftp上设置了登录信息,以便访问仅限于特定的文件夹。为什么?



以下是代码(在此先感谢!):

 #!/ bin / bash 

#get用户名和密码
USER =用户名
PASS =密码

HOST =myftpserver.com / users / user1 /#here我只尝试过指定服务器名称以及包括整个路径
LCD =〜/ Desktop / localfolder /
RCD =users / user1 /

lftp -cset ftp:list-options -a;
open ftp:// $ USER:$ PASS @ $ HOST;
lcd $ LCD;
mirror -c --reverse --verbose $ LCD $ RCD#我试过了几个不同的选项,不带结果


解决方案

你可能不再需要这个了(4年后),但我会更新它,如果有人在这里遇到同样的问题, p>

如果您想将FTP服务器文件夹与您文件夹中的内容同步,则应该使用类似这样的内容。

 #!/ bin / bash 

#get usern ame和密码
USER =用户名#您的用户名
PASS =密码#您的密码
HOST =myftpserver.com#只保存地址
LCD =〜/桌面/ localfolder#本地目录
RCD =/ users / user#FTP服务器目录

lftp -f
打开$ HOST
用户$ USER $ PASS
lcd $ LCD
mirror --continue --reverse --delete --verbose $ LCD $ RCD
bye

如果要使用它从本地文件夹同步到FTP服务器,只需删除--reverse和swap镜像命令中的文件夹。


$ b

 #!/ bin / bash 

#get用户名和密码
USER =用户名#您的用户名
PASS =密码#您的密码
HOST =myftpserver.com#只保存地址
LCD = 〜/ Desktop / localfolder#你的本地目录
RCD =/ users /用户#FTP服务器目录

lftp -f
打开$ HOST
用户$ USER $ PASS
lcd $ LCD
镜像 - 继续 - -delete --verbose $ RCD $ LCD
bye

要做类似于你在问题中所评论的内容,请同时使用两种方法并保留每个值的最新值,我不相信仅使用lftp就可能需要某些东西来检测变化并决定哪个脚本使用。


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

解决方案

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.

If you want to sync the FTP server folder with the content in your folder you should use something like this

#!/bin/bash

#get username and password
USER=username                   #Your username
PASS=password                   #Your password
HOST="myftpserver.com"          #Keep just the address
LCD="~/Desktop/localfolder"     #Your local directory
RCD="/users/user"               #FTP server directory

lftp -f "
open $HOST
user $USER $PASS
lcd $LCD
mirror --continue --reverse --delete --verbose $LCD $RCD
bye
" 

And if you want to use it to sync from your local folder to the FTP server simply remove the --reverse and swap the folders in the mirror command.

#!/bin/bash

#get username and password
USER=username                   #Your username
PASS=password                   #Your password
HOST="myftpserver.com"          #Keep just the address
LCD="~/Desktop/localfolder"     #Your local directory
RCD="/users/user"               #FTP server directory

lftp -f "
open $HOST
user $USER $PASS
lcd $LCD
mirror --continue --delete --verbose $RCD $LCD
bye
" 

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.

这篇关于使用lftp将本地文件夹与ftp文件夹同步的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆