简体   繁体   English

使用 lftp 将本地文件夹与 ftp 文件夹同步的语法?

[英]Syntax for using lftp to synchronize local folder with an ftp folder?

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).它应该有两种方式,始终保持文件夹最新(我使用常规的 cronjob)。 However, first I do not get the two way file transfer to work (it just downloads from the ftp and not the opposite).但是,首先我没有让双向文件传输工作(它只是从 ftp 下载,而不是相反)。

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.其次,它从 ftp 下载全部内容,即使登录信息已在 ftp 上设置,因此访问仅限于特定文件夹。 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. 你可能不再需要这个了(迟了4年),但我会更新这个,如果有人在这里遇到同样的问题,这里有一个帮助。

If you want to sync the FTP server folder with the content in your folder you should use something like this 如果要将FTP服务器文件夹与文件夹中的内容同步,则应使用类似这样的内容

#!/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. 如果要将其用于从本地文件夹同步到FTP服务器,只需删除--reverse并在mirror命令中交换文件夹即可。

#!/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可能需要检测更改并决定使用哪个脚本。

if sync the remote FTP server folder to the local folder and using lftp-4.9 above, please try this script:如果将远程 FTP 服务器文件夹同步到本地文件夹并使用上述 lftp-4.9,请尝试以下脚本:

#!/bin/bash

LFTP_HOME=/home/lftp-4.9.2
#get username and password
REMOTE_FTP_USER="user"
REMOTE_FTP_PASS="passwd"
REMOTE_HOST="ftp-server"
REMOTE_PORT="ftp-pport"
LOCAL_FOLDER="/home/ftpRoot/backup_mirror/"
REMOTE_FOLDER="/"

cd $LOCAL_FOLDER
$LFTP_HOME/bin/lftp -f "
open -p $REMOTE_PORT $REMOTE_HOST
user $REMOTE_FTP_USER $REMOTE_FTP_PASS
mirror -c -e --verbose --target-directory=$LOCAL_FOLDer $REMOTE_FILDER
bye
"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM