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

标签 linux ftp sync synchronize

我想同步两个文件夹。它应该有两种方式,始终保持文件夹最新(我使用常规的 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

最佳答案

你可能不再需要它了(晚了 4 年),但我会更新它,如果有人在这里遇到同样的问题,这里会提供帮助。

本地目录到FTP服务器目录

如果你想将 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
" 

FTP 服务器目录到您的本地目录

只需删除 --reverse 并交换镜像命令中的文件夹即可。

#!/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
" 

要像您在问题中评论的那样做一些事情,同步两种方式并保留每种方式的最新值,我认为单独使用 lftp 是不可能的,您需要一些东西来检测更改并决定使用哪个脚本。

关于linux - 使用 lftp 将本地文件夹与 ftp 文件夹同步的语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5245968/

相关文章:

linux - 在 Golang 中统计 linux 上的进程

linux - 如何在 64 位 RHEL 5.4 上升级 glibc

linux - splinter 的 Mercurial repo

javascript - 对 FTP 服务器执行跨域 XMLHTTPREQUEST 的语法是什么?

php - 同步多个 iCalendar(Airbnb、Flipkey、Google 日历等)

Android - 如何在失败时重新安排同步请求

在尝试写入之前检查管道是否损坏?

linux -/etc/vsftpd/_vsftpd.conf : binary operator expected on Red Hat

bash - 从文件复制文件列表

database - 这是功能同步算法吗?