如何重定向结果"!find ..."命令来放置lftp命令

Lui*_*ura 5 linux ftp shell lftp

我想从lftp中放入来自!find命令的结果的文件.

我试过了:

$> lftp -u foo, sftp://bar
lftp foo@bar$> put < !find ./local -type f
Run Code Online (Sandbox Code Playgroud)

但失败了!!

这有效:

$> lftp -u foo, sftp://bar
lftp foo@bar$> !find ./local -type f | awk '{print "put "$1}' > /tmp/files.lftp
lftp foo@bar$> source /tmp/files.lftp
Run Code Online (Sandbox Code Playgroud)

还有另一种方式!?我想使用stdio重定向(管道,stdin ......).

TMS*_*TMS 4

我已经通读了整个man lftp(1),看来你选择的方式实际上是最好的一种

  1. !正如您所尝试的那样,命令不支持与其他命令直接组合put < !find ...
  2. 上传文件的唯一方法是使用put,mputmirrormirror正如您所指出的,对您没有用,因为它保留了路径。
  3. putmput命令不支持任何方式来指定带有要上传的文件列表的文件。

因此,唯一的可能性就是您所拥有的:生成脚本并用于source运行它。

您可以尝试的是将所有文件放入一个mput命令中:

!find ./local -type f | awk -v ORS=" " 'BEGIN{print "mput "}{print}' > /tmp/files.lftp
Run Code Online (Sandbox Code Playgroud)

但要小心:虽然我没有在文档中找到它,但最大行大小可能有限制!所以我认为最终你的方式是最好的方式。

请注意,您还可以对命令进行代码高尔夫:

!find ./local -type f -printf "put %p\n" > /tmp/files.lftp
Run Code Online (Sandbox Code Playgroud)