Рекурсивно помещать файлы на удаленный сервер с помощью FTP

В настоящее время я нахожусь в ситуации, когда у меня очень ограниченный доступ к серверу, но мне нужно загружать и скачивать значительное количество файлов, содержащихся в одной структуре каталогов. У меня нет доступа к SSH, поэтому я не могу использовать SCP — и, к сожалению, rsync тоже не подходит.

В настоящее время я использую ncftpput, это здорово, но кажется довольно медленным (несмотря на быстрое соединение).

Есть ли альтернативный/лучший метод, который я мог бы изучить?

(Пожалуйста, примите мои извинения, если это было освещено, я провел быстрый поиск перед публикацией, но не нашел ничего, что конкретно отвечало бы на мой вопрос)


person codeinthehole    schedule 10.09.2009    source источник
comment
для ncftp — используете ли вы команду put -R для рекурсивной загрузки каталога?   -  person DmitryK    schedule 10.09.2009
comment
Я действительно - я думаю, что часть проблемы заключается в том, что FTP довольно устарел ... поэтому может не быть идеального решения.   -  person codeinthehole    schedule 10.09.2009


Ответы (5)


Попробуйте использовать LFTP: http://lftp.yar.ru/

или YAFC: http://yafc.sourceforge.net/index.php

person DmitryK    schedule 10.09.2009
comment
Большое спасибо за это .. Я только что скомпилировал YAFC, и это кажется очень хорошим - person codeinthehole; 10.09.2009


Я не знаком с ncftpput. Для неинтерактивного FTP я всегда использовал модуль Perl Net::FTP -- http://perldoc.perl.org/Net/FTP.html

Это будет быстрее, потому что вы можете войти в систему, а затем выполнить все передачи сразу (на первый взгляд кажется, что вы выполняете ncftpput один раз для каждого файла get/put).

Просто помните, что НИКОГДА не используйте искажение ASCII! Это значение по умолчанию, поэтому используйте:

$ftp->binary

Искажение ASCII должно умереть в одном огне с автоматической интерпретацией часового пояса MySQL.

person audiodude    schedule 10.09.2009

Поскольку у меня всегда возникают проблемы с этим, я опубликую свои заметки здесь:

Одна вещь, которую я всегда путаю, это синтаксис; поэтому ниже приведен тестовый скрипт 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 в разделе Как мне временно запустить FTP-сервер? - Спросите Ubuntu; и ftpsync находится здесь: FTPsync (однако обратите внимание, что он глючит; см. также Search/grep ftp имена удаленных файлов - 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:[email protected]/
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:[email protected]/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:[email protected]/

{ 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:[email protected]/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
person sdaau    schedule 02.03.2014

Нет упоминания о ncftp?

В Ubuntu sudo apt install ncftp

person Paul Williams    schedule 09.12.2019