sftp_.sh: line 13: warning: here-document at line 7 delimited by end-of-file (wanted `EOF')
ls: cannot access file*.txt: No such file or directory
Unknown command `SOURCE_FILE='.
get: Access failed: Failure
I made sure that files exist in the directory but still it is the showing "No such file or dierctory" error..
Could anyone please help me on this ?
---------- Post updated at 05:34 AM ---------- Previous update was at 04:45 AM ----------
The below code is sending all the files but I need to send only the latest file only.
The ls command is run on the local machine, not the remote machine.
You could find the name of the most recent file in a first call to lftp . You can write the output into a temporary file, grep the filename out and then call lftp a second time to actually transfer the file.
But it doubles the work... if not wrong...I had the below ftp code and expected the same can be done to the sftp also.. In case you are right.. but Is there any other way(jst like below ftp code)
cd /mypath/
SOURCE_FILE=$(ls -rt myfile*.DAT |tail -l)
ftp -i -n -v <<-!
open myipaddress
user "IUSER\netrep1" 1132115c
lcd /localpath/
cd /remotePath/
put "$SOURCE_FILE"
close
quit
!
echo 'The file has been successfully FTPed to the server'
The here document is completely prepared, before "lftp" is started. So it cannot react on lftp's output.
Another hint would be to try "expect". It is a tool to interact with programs and react on their outputs, often used to control telnet/ssh/ftp/...-sessions.