0

I trying to run a script that get a latest file create in my FTP server.

file=`ls -t -r | tail -n 1`

sudo lftp <<FTP
open $hostname
user $username $password
cd $folder
get $file
bye
FTP

But the ls command in file variable execute in my local machine. What´s wrong? Thank you.

A.Verta
  • 71
  • 1
  • 1
  • 7
  • Are you confusing `$file` with `$arquivo`? – Jens Jan 02 '13 at 19:29
  • yes, you're right, `ls` *is* being executed on your local machine. you'll need to run a preliminary ftp where the only commands you issue are `cd ... AND ls` AND then you need to capture that output (as you have done with file), AND then you need to parse that multi-line variable to find the newest file and store that as `file=`. Good luck. – shellter Jan 02 '13 at 19:33

1 Answers1

0

Using cls instead of ls will help. Change get $file to

cls -1t|sed -n 1s/^/get\\ /p>/tmp/get
source /tmp/get

Beware, this uses the file /tmp/get and is not suited for concurrent operation.

Armali
  • 18,255
  • 14
  • 57
  • 171