I need to run a test SFTP command in a batch mode and what I need to prompt my password after the sftp userid@hostname. I do not have have an ssh key exchanged between my server and the external server. I only have access to it as an sftp server. I must enter my password in my script. How do i do that.
Here I have and it is not working:
SourceHost='157.155.0.45'
loginid='nftpX1'
Pass='XFP1'
SourceDir='MA/08_24_2014/'
TargetDir='/tmp/ftp/'
GetDate=`date '+%d-%m-%Y'`
sftp $loginid@$SourceHost << !
send "$Pass\n"
cd $SourceDir
mget *$GetDate* $TargetDir
bye
!
exit
Did you try transerring your public key via sftp to the server so that you would not have to prompt for a password. Note: sftp provides a batch (-b) mode but it's not for entering a password. You can use a program like expect to send the password (but try transferring your public key to your remote directory under ~/.ssh/authorized_keys)
1 Like
Like i said, we are not allowed to transfer public keys to the remote dir. Only to get files. This will not work. Thanks anyway
---------- Post updated at 01:58 PM ---------- Previous update was at 01:56 PM ----------
---------- Post updated at 01:58 PM ---------- Previous update was at 01:58 PM ----------
I figured out finally. This will work by using the lftp option. This is the only way where you can test a password in a batch SFTP script.
lftp -u $loginid,$Pass sftp://$SourceHost << --EOF--
mget $SourceDir/*$GetDate*
quit
--EOF--