当前位置: 首页 > news >正文

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

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

有一件事我总是搞混了,那就是语法;所以下面有一个

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

(如果它不存在,将创建它)。

以下是

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:

[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

相关文章:

  • linux下载ccle数据,对CCLE数据库可以做的分析--转载
  • linux 什么是io,Linux异步IO是什么?
  • linux基础实验报告6,Linux实验报告6参考解析.doc
  • c语言树的类型作用是什么,C语言数据的基本类型有哪些?
  • c语言作业二闰年,浙大版《C语言程序设计(第3版)》题目集 练习3-5 输出闰年 (15 分)...
  • 汇编语言与c 混合编程,汇编语言与C C 混合编程精选.ppt
  • c语言链式表,c语言实现数据结构中的链式表
  • socket双向通信c语言,WebSocket实现实时双向通信
  • 递归函数c语言求分段函数,Python 实现递归函数求解分段函数表达式;并解释递归函数其原理...
  • c语言验证完成排序算法的时间,排序算法的时间复杂度和空间复杂度
  • c语言租游艇算法思路,租用游艇问题(C或C)长江游艇俱乐部在长江上设置了n个游艇出租站 爱问知识人...
  • 陕科大c语言题库,C语言考试题库
  • linux设置url转发,Apache+Weblogic实现URL转发
  • android 广播注册多次,记一次安卓开发广播重复注册的解决方案
  • Android封装拍照sdk,Android 短视频拍摄、拍照滤镜 第三方库SDK