0

I have a sftp script and i am trying to connect a sftp directory and copy files into my local machine .I the remote sftp directory i have a file 'note.lst' that file contains the file name's which i need to import from ftp to local directory .

 sftp
 cd  /root/ftp1
 lcd /root/foleder1
 cat note.lst > ${2}
 mget ${2}
 bye

In the above command line i was trying to cat the list file and move the data of the cat o/p into the variable ${2} and mget them .

The below approach is not working .Can any one help me .

Thank you.

  • 2
    Are you trying to use FTP or sftp? – DopeGhoti Oct 25 '17 at 17:57
  • Here i am using sftp sir ! – Rak kundra Oct 25 '17 at 17:59
3

You'll probably want to break this into two operations: one to fetch the list, and one to fetch the listed files.

# Fetch the list
scratch=$(mktemp -d)
trap "rm -fr $scratch" EXIT
scp user@host:/root/ftp1/note.lst $scratch/filelist.txt
# transmogrigy the list into the SFTP script:
awk 'BEGIN{ print "lcd /root/foleder1"; print "cd /root/ftp1" } { print "get \"" $0 "\"" }' > $scratch/script.sftp
# execute the SFTP script
sftp -b $scratch/script.sftp user@host

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.