Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect result "!find ..." command to put lftp command

I'd like to put files from result of !find command from lftp.

I tried:

$> lftp -u foo, sftp://bar
lftp foo@bar$> put < !find ./local -type f

But failed!!

This worked:

$> 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

Is there another way!? I'd like to use stdio redirects (pipes, stdin...).

like image 283
Luiz Coura Avatar asked Aug 06 '12 21:08

Luiz Coura


1 Answers

I have read through the whole man lftp(1) and it seems that the way you have chosen is actually the best one.

  1. ! command doesn't support direct combination with another commands, as you tried put < !find ...
  2. The only way to upload files is using put, mput or mirror. mirror is of no use for you as you noted, because it preserves the path.
  3. put or mput commands don't support any means to specify a file with list of files to upload.

So, the only possibility is what you have: generate the script and use source to run it.

What you could try is to put all the files into one mput command:

!find ./local -type f | awk -v ORS=" " 'BEGIN{print "mput "}{print}' > /tmp/files.lftp

but be careful: although I haven't found it in the docs, there might be limitation for maximum line size! So I think in the end your way is the best way to go.

Note that you can also code-golf your command to:

!find ./local -type f -printf "put %p\n" > /tmp/files.lftp
like image 53
Tomas Avatar answered Sep 24 '22 20:09

Tomas