Linux 如何在rsync中通过FTP复制所有文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5986942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:03:33  来源:igfitidea点击:

How to copy all files via FTP in rsync

linuxftprsync

提问by Mahakaal

I have online account with some Host which give me FTP account with username and password .

我有一些主机的在线帐户,它为我提供了带有用户名和密码的 FTP 帐户。

i have another with copany which gave me FTP and rsync .

我有另一个公司,它给了我 FTP 和 rsync。

Now i want to transfer all my files from old FTP to NEW FTP with rync.

现在我想使用 rync 将我所有的文件从旧的 FTP 传输到新的 FTP。

Now is it possible to do it via rsync only because i don't want to first copy on computer and then upload again

现在是否可以通过 rsync 进行操作,因为我不想先在计算机上复制然后再次上传

采纳答案by sarnold

Lets call the machine with only FTP src.

让我们只用 FTP 调用机器src

Lets call the machine with FTP and SSH dst.

让我们用 FTP 和 SSH 调用机器dst

ssh dst
cd destination-direction
wget --mirror --ftp-user=username --ftp-password=password\
     --no-host-directories ftp://src/pathname/

Note that running wgetwith --ftp-passwordon the command line will give away the password to anyone else on the system. (As well as transferring it over the wire in the clear, but you knew that.)

请注意,在命令行上运行wgetwith--ftp-password会将密码泄露给系统上的任何其他人。(以及以明文方式通过电线传输它,但您知道这一点。)

If you don't have access to wget, then they might have ncftpor lftpor ftpinstalled. I just happen to know wgetthe best. :)

如果您无权访问wget,则他们可能已安装ncftplftpftp已安装。我只是碰巧知道wget最好的。:)

EditTo use ftp, you'll need to do something more like:

编辑要使用ftp,您需要执行以下操作:

ftp src
user username
pass password
bin
cd /pathname
ls

At this point, note all the directories on the remote system. Create each one with !mkdir. Then change into the directory both locally and remotely:

此时,请注意远程系统上的所有目录。用!mkdir. 然后在本地和远程切换到目录:

lcd <dirname>
cd <dirname>
ls

Repeat for all the directories. Use mget *to get all the files.

对所有目录重复此操作。使用mget *得到的所有文件。

If this looks awful, it is because it is. FTP wasn't designed for this, and if your new host doesn't have better tools (be sure to look for ncftpand lftpand maybe something like ftpmirror), then either compile better tools yourself or get good at writing scripts around the bad tools. :)

如果这看起来很糟糕,那是因为它确实如此。FTP不是为这个,如果你的新主机没有更好的工具(一定要寻找ncftplftp,也许有点像ftpmirror),然后要么自己编译更好的工具,或者在写周围的坏工具脚本得到很好的。:)

Or if you could get a shell on src, that'd help immensely too. FTP is just not intended for transferring thousands of files.

或者,如果您可以在 上安装一个外壳src,那也会有很大帮助。FTP 不适合传输数千个文件。

Anyway, this avoids bouncing through your local system, which ought to help throughput significantly.

无论如何,这可以避免在您的本地系统中弹跳,这应该会显着提高吞吐量。

回答by Ryan C. Thompson

There's always the trusty FUSE filesystems, CurlFtpFSand SSHFS. Mount each server with the appropriate filesystem and copy across using standard utilities. Probably not the fastest way to do it, but quite possibly the least labor-intensive.

总是有值得信赖的 FUSE 文件系统,CurlFtpFSSSHFS。使用适当的文件系统挂载每个服务器并使用标准实用程序进行复制。可能不是最快的方法,但很可能是劳动密集度最低的方法。

回答by David

I was looking for a simple solution to sync a remote folder to a local folder via FTP while only replacing new files. I got stuck with a little wgetscript based on sarnold's answerthat I thought might be helpful to others, too, so here it is:

我正在寻找一种简单的解决方案,通过 FTP 将远程文件夹同步到本地文件夹,同时只替换新文件。我遇到了一个wget基于sarnold回答的小脚本,我认为它也可能对其他人有帮助,所以这里是:

#!/bin/bash    
HOST="1.2.3.4"
USER="username"
PASS="password"
LDIR="/path/to/local/dir"    # can be empty
RDIR="/path/to/remote/dir"   # can be empty

cd $LDIR && \                # only start if the cd was successful
wget \
  --continue \               # resume on files that have already been partially transmitted
  --mirror \                 # --recursive --level=inf --timestamping --no-remove-listing
  --no-host-directories \    # don't create 'ftp://src/' folder structure for synced files
  --ftp-user=$USER \
  --ftp-password=$PASS \
    ftp://$HOST/$RDIR