代码之家  ›  专栏  ›  技术社区  ›  codeinthehole

使用ftp递归地将文件放入远程服务器

  •  3
  • codeinthehole  · 技术社区  · 16 年前

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

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

    我是否有其他/更好的方法可以研究?

    (请接受我的道歉如果这已经被涵盖,我在发布前做了一个快速搜索,但没有找到任何具体回答我的问题)

    4 回复  |  直到 11 年前
        1
  •  4
  •   DmitryK    16 年前
        2
  •  2
  •   Ryan C. Thompson    16 年前

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

        3
  •  1
  •   audiodude    16 年前

    我不熟悉 ncftpput .对于非交互式ftp,我总是使用perl net::ftp模块-- http://perldoc.perl.org/Net/FTP.html

    这将更快,因为您可以登录,然后一次完成所有传输(从粗略的一瞥看,您似乎执行了 NCFTPUT 每个文件获取/放置一次)。

    记住不要使用ASCII格式!这是默认值,因此请使用:

    $ftp->binary
    

    ascii管理需要与mysql自动时区解释在同一个火灾中死亡。

        4
  •  0
  •   Community Mohan Dere    8 年前

    因为我总是会遇到这个问题,所以我会把我的笔记贴在这里:

    有一件事我总是搞混了,那就是语法;所以下面有一个 bash 测试人员脚本,它创建一些临时目录,然后启动一个临时ftp服务器,并比较 rsync (在纯本地文件模式下,因为它不支持ftp) lftp ftpsync .

    事情是-你可以用 rsync /path/to/local /path/to/remote/ ,rsync会自动发现 local 在下创建的子目录 remote 然而,为了 LFTP FTPSYNC 手动指定目标目录,如 ... /path/to/local /path/to/remote/local (如果它不存在,将创建它)。

    你可以找到 ftpserver-cli.py 在里面 How do I temporarily run an FTP server? - Ask Ubuntu FTPSYNC 这里是: 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
    

    这里是 普什图 脚本:

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