user1760560
user1760560

Reputation: 21

lftp + bash script + variables

I'm using lftp to mirror files from external server but now what I need is to after sucessful download rename source directory (on remote server). Basicaly what I need is to open connection on remote server list directories, download all dirs that name starts from "todo" i.e. todo.20121019 after sucess I must rename downloaded directory to "done.20121019". There might be more than one dir on the server.

Remote FTP server works only with active connection.

#!/bin/bash

directories=`lftp -f lftp_script_file.lf |grep done|awk '{print $NF}'`

for i in $directories
  do
    echo $i //here I get list of directories that should be downloaded and renamed
  done

lftp_script_file.lf just list directires:

set ftp:passive-mode false;
open ftp://user:[email protected]
ls my_sub_dir/

Is there a way to:

  1. open connection to ftp server
  2. find directories that I want to download
  3. add those dirs to queue and download
  4. rename directories on remote server

in batch file?

What I was trying to achive was to list dirs find interesing ones, download and rename but I cant find a way to post list of dirs to lftp via bash script and "set ftp:passive-mode false".

Upvotes: 2

Views: 7308

Answers (1)

Denis Shatov
Denis Shatov

Reputation: 41

To be able to substitute variables into lftp commands use something like this:

lftp -e "cmd1;cmd2"

Upvotes: 4

Related Questions