【问题标题】:Recursively PUT files to a remote server using FTP使用 FTP 递归地将文件放到远程服务器上
【发布时间】:2010-11-27 01:09:22
【问题描述】:

我目前的情况是,我对服务器的访问权限非常有限,但需要上传和下载包含在单个目录结构中的大量文件。我没有 SSH 访问权限,所以我不能使用 SCP - 不幸的是,rsync 也不是一个选项。

我目前正在使用 ncftpput,它很棒,但似乎很慢(尽管连接速度很快)。

我可以研究一下替代/更好的方法吗?

(如果这已经涉及,请接受我的道歉,我在发布之前进行了快速搜索,但没有找到任何具体回答我的问题的内容)

【问题讨论】:

  • 对于 ncftp - 您是否使用“put -R”命令进行递归目录上传?
  • 我确实 - 我认为部分问题是 FTP 已经过时了.. 所以可能没有理想的解决方案

标签: recursion ftp data-transfer put ftp-client


【解决方案1】:

【讨论】:

  • 非常感谢这些..我刚刚编译了YAFC,看起来很不错
【解决方案2】:

如果您的连接良好,我建议您通过 GNOME 或 KDE 文件管理器安装 ftp 服务器,或者使用CurlFtpFS。然后你可以把它当作另一个文件夹。

【讨论】:

  • 这是一个可怕的答案。这样做不可能比 FTP 更快,而且风险更大,尤其是在数据量很大的情况下,因为它不支持中断时恢复。如果他无法访问 SSH,他将如何配置它以进行挂载?
  • 不需要服务器配置。服务器已配置为 FTP。重点不是让事情变得更快,而是让事情变得更容易。使用 CurlFtpFS 安装后,曾经可以使用标准的 unix utils,如 cp 和 rsync。我确实说过连接良好时效果最好。
【解决方案3】:

我不熟悉ncftpput。对于非交互式 FTP,我一直使用 Perl Net::FTP 模块 -- http://perldoc.perl.org/Net/FTP.html

这会更快,因为您可以登录,然后一次执行所有传输(粗略一看,您似乎对每个文件 get/put 执行一次 ncftpput)。

请记住永远不要使用 ASCII 修改!这是默认设置,所以使用:

$ftp->binary

ASCII 修改需要与 MySQL 自动时区解释同火。

【讨论】:

    【解决方案4】:

    由于我总是遇到这个问题,所以我会在这里发布我的笔记:

    我总是混淆的一件事是语法;所以下面有一个bash 测试器脚本,它创建一些临时目录,然后启动一个临时ftp 服务器,并将rsync(在纯本地文件模式下,因为它不支持ftp)与lftp 和@987654327 进行比较@。

    问题是——你可以使用rsync /path/to/local /path/to/remote/,rsync 会自动发现你想要在remote 下创建一个local 子目录;但是,对于lftpftpsync,您必须 手动指定目标目录,如... /path/to/local /path/to/remote/local (如果它不存在,则会创建它)。

    您可以在How do I temporarily run an FTP server? - Ask Ubuntu 中找到ftpserver-cli.pyftpsync 在这里:FTPsync(但是,请注意它有问题;另请参阅 Search/grep ftp remote filenames - Unix & Linux Stack Exchange);

    这是puttest.sh 脚本的简短输出,显示了不同情况下的递归放置行为:

    $ bash puttest.sh 
    Recreate directories; populate loctest, keep srvtest empty:
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    
    *NOTE, rsync can automatically figure out parent dir:
    + rsync -a --exclude '*.git*' /tmp/loctest /tmp/srvtest/
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    └── loctest
        └── tempa1.txt
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    cleanup:
    + rm -rf /tmp/srvtest/loctest
    
    Start a temporary ftp server:
    + sudo bash -c 'python /path/to/pyftpdlib/ftpserver-cli.py --username=user --password=12345 --directory=/tmp/srvtest &'
    + sleep 1
    Using: user: user pass: 12345 port: 21 dir: /tmp/srvtest
    [I 14-03-02 23:24:01] >>> starting FTP server on 127.0.0.1:21, pid=21549 <<<
    [I 14-03-02 23:24:01] poller: <class 'pyftpdlib.ioloop.Epoll'>
    [I 14-03-02 23:24:01] masquerade (NAT) address: None
    [I 14-03-02 23:24:01] passive ports: None
    [I 14-03-02 23:24:01] use sendfile(2): False
    test with lftp:
    
    *NOTE, lftp syncs *contents* of local dir (rsync-like syntax doesn't create target dir):
    + lftp -e 'mirror -R -x ".*\.git.*" /tmp/loctest / ; exit' -u user,12345 127.0.0.1
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    └── tempa1.txt
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    cleanup:
    + rm -rf /tmp/srvtest/tempa1.txt
    
    *NOTE, specify lftp target dir explicitly (will be autocreated):
    + lftp -e 'mirror -R -x ".*\.git.*" /tmp/loctest /loctest ; exit' -u user,12345 127.0.0.1
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    └── loctest
        └── tempa1.txt
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    cleanup:
    + sudo rm -rf /tmp/srvtest/loctest
    
    *NOTE, ftpsync syncs *contents* of local dir (rsync-like syntax doesn't create target dir); also info mode -i is buggy (it puts, although it shouldn't):
    
    *NOTE, ftpsync --ignoremask is for older unused code; use --exclude instead (but it is buggy; need to change  in source)
    + /path/to/ftpsync/ftpsync -i -d '--exclude=.*\.git.*' /tmp/loctest ftp://user:12345@127.0.0.1/
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    └── tempa1.txt
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    cleanup:
    + sudo rm -rf /tmp/srvtest/tempa1.txt
    
    *NOTE, specify ftpsync target dir explicitly (will be autocreated):
    + /path/to/ftpsync/ftpsync -i -d '--exclude=.*\.git.*' /tmp/loctest ftp://user:12345@127.0.0.1/loctest
    show dirs:
    + tree --noreport -a /tmp/srvtest /tmp/loctest
    /tmp/srvtest
    └── loctest
        └── tempa1.txt
    /tmp/loctest
    ├── .git
    │   └── tempa2.txt
    └── tempa1.txt
    cleanup:
    + sudo rm -rf /tmp/srvtest/loctest
    + sudo pkill -f ftpserver-cli.py
    

    还有,这是puttest.sh 脚本:

    #!/usr/bin/env bash
    set -x
    
    # change these to match your installations:
    FTPSRVCLIPATH="/path/to/pyftpdlib"
    FTPSYNCPATH="/path/to/ftpsync"
    
    { echo "Recreate directories; populate loctest, keep srvtest empty:"; } 2>/dev/null
    
    sudo rm -rf /tmp/srvtest /tmp/loctest
    
    mkdir /tmp/srvtest
    
    mkdir -p /tmp/loctest/.git
    echo aaa > /tmp/loctest/tempa1.txt
    echo aaa > /tmp/loctest/.git/tempa2.txt
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo -e "\n*NOTE, rsync can automatically figure out parent dir:"; } 2>/dev/null
    
    rsync -a --exclude '*.git*' /tmp/loctest /tmp/srvtest/
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo "cleanup:"; } 2>/dev/null
    rm -rf /tmp/srvtest/*
    
    { echo -e "\nStart a temporary ftp server:"; } 2>/dev/null
    
    # https://askubuntu.com/questions/17084/how-do-i-temporarily-run-an-ftp-server
    
    sudo bash -c "python $FTPSRVCLIPATH/ftpserver-cli.py --username=user --password=12345 --directory=/tmp/srvtest &"
    sleep 1
    
    { echo "test with lftp:"; } 2>/dev/null
    # see http://russbrooks.com/2010/11/19/lftp-cheetsheet
    # The -R switch means "reverse mirror" which means "put" [upload].
    { echo -e "\n*NOTE, lftp syncs *contents* of local dir (rsync-like syntax doesn't create target dir):"; } 2>/dev/null
    
    lftp -e 'mirror -R -x ".*\.git.*" /tmp/loctest / ; exit' -u user,12345 127.0.0.1
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo "cleanup:"; } 2>/dev/null
    rm -rf /tmp/srvtest/*
    
    { echo -e "\n*NOTE, specify lftp target dir explicitly (will be autocreated):"; } 2>/dev/null
    
    lftp -e 'mirror -R -x ".*\.git.*" /tmp/loctest /loctest ; exit' -u user,12345 127.0.0.1
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo "cleanup:"; } 2>/dev/null
    sudo rm -rf /tmp/srvtest/*
    
    { echo -e "\n*NOTE, ftpsync syncs *contents* of local dir (rsync-like syntax doesn't create target dir); also info mode -i is buggy (it puts, although it shouldn't):"; } 2>/dev/null
    { echo -e "\n*NOTE, ftpsync --ignoremask is for older unused code; use --exclude instead (but it is buggy; need to change `  'exclude=s' => \$opt::exclude,` in source)"; } 2>/dev/null
    
    $FTPSYNCPATH/ftpsync -i -d --exclude='.*\.git.*' /tmp/loctest ftp://user:12345@127.0.0.1/
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo "cleanup:"; } 2>/dev/null
    sudo rm -rf /tmp/srvtest/*
    
    { echo -e "\n*NOTE, specify ftpsync target dir explicitly (will be autocreated):"; } 2>/dev/null
    
    $FTPSYNCPATH/ftpsync -i -d --exclude='.*\.git.*' /tmp/loctest ftp://user:12345@127.0.0.1/loctest
    
    { echo "show dirs:"; } 2>/dev/null
    tree --noreport -a /tmp/srvtest /tmp/loctest
    
    { echo "cleanup:"; } 2>/dev/null
    sudo rm -rf /tmp/srvtest/*
    
    
    sudo pkill -f ftpserver-cli.py
    
    { set +x; } 2>/dev/null
    

    【讨论】:

      【解决方案5】:

      没有提到ncftp

      在 Ubuntu 中,sudo apt install ncftp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-15
        • 2021-07-06
        • 1970-01-01
        • 2018-02-24
        • 1970-01-01
        • 1970-01-01
        • 2016-02-08
        • 1970-01-01
        相关资源
        最近更新 更多