Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sftp file into the target system with encrypted password

Status
Not open for further replies.

viswa759

IS-IT--Management
Nov 30, 2012
1
0
0
IN
We are praparing a script to move a file from AIX 6.1 to other system.

we are using the below script"put_etransfer.ksh"
#!/usr/bin/ksh
sftpdate=`date +"%Y%m%d%H%M"`
filename=hsa-selectacc.asc
logfile=/home/data/interfaces/log/etransfer_$sftpdate.log
cd /home/data/usinterfaces/out
if ! -e $FILENAME
then
print "ERROR - $FILENAME does not exist."
print "Exitting ..."
exit 1
fi
/usr/local/bin/sftp -B /home/hrdata/scripts/USsftp/cmdc.sftp qaz00100@move.etransfer.com >> $logfile

here cmdc.sftp conatains below commands
binary
ls -l
put hsa-selectacc.asc
exit
==========================================================
when we execute put_etransfer.ksh we get error message

./put_esecuretransfer.ksh
Error: Could not open connection to `qaz00100@move.etransfer.com': Could not connect to `move.etransfer.com': Disconnected by application
when I change the script to

#!/usr/bin/ksh
sftpdate=`date +"%Y%m%d%H%M"`
FILENAME=hsa-selectacc.asc
logfile=/home/hrdata/usinterfaces/log/etransfer_$sftpdate.log
cd /home/hrdata/usinterfaces/out
if ! -e $FILENAME
then
print "ERROR - $FILENAME does not exist."
print "Exitting ..."
exit 1
fi
sftp qaz00100@move.etransfer.com
and execute the script put_etransfer.ksh
It will ask for password and if I provide the password it will get connected but i need to give the command put hsa-selectacc.asc

Can any one help me on this.

Thanks inadvance
Viswanath
 
Alright Viswanath try this.

#!/usr/bin/ksh
SFTPDATE=`date +"%m%d%Y"`
FILENAME="hsa-selectacc.asc"
LOGFILE=/home/hrdata/usinterfaces/log/etransfer_$SFTPDATE.log
cd /home/hrdata/usinterfaces/out
if [[ -e $FILENAME ]]
then
sftp qaz00100@move.etransfer.com << EOF
put hsa-selectacc.asc
exit
EOF
print "The File is successfully copied" >> $LOGFILE
else
print "ERROR - $FILENAME does not exist." >> $LOGFILE
print "Exiting ..." >> $LOGFILE
exit 1
fi


Let me know how it goes.

Also you can use ssh key pair for password less authentication. (In this situation you don't even need a password).

SARFARAZ AHMED SYED,
Sr. Systems Engineer
 
Oh, forgot to add " " on log file

Please make sure you add " " (double quotation)
LOGFILE="/home/hrdata/usinterfaces/log/etransfer_$SFTPDATE.log"

SARFARAZ AHMED SYED,
Sr. Systems Engineer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top