I need to copy few files from a remote directory which has subdirectories within it. I am using lftp to do that but shell commands inside it aren't working. Is there a workaround for this? Please see code below. Any help is much appreciated guys!
lftp -u $USER,$PASS sftp://$HOST <<EOF 2>&1
#find file file_name with absolutepath from REMOTE_DIR which lies in any of its subdirectories
filefound=`find "${REMOTE_DIR}"`-name "{$file_name}"`
#Get the absolutepath for subdirectory where the file resides
dir_loc=`dirname "${filefound}"`
lcd ${LOCAL_DIR}
cd ${dir_loc}
get ${file_name}
bye
EOF
The error I am getting is: filefound: command not found dir_loc:command not found
That's a conceptual misunderstanding.
You cannot run shell commands using SFTP client. To run shell commands use an SSH client.