Swadhin Ray
asked on
SFTP script
Hello Experts,
I was using the script to move the file from my server to external server using "expect" , but my production server is not having the "expect" library present and network team is not allowing to configure it.
My SFTP script was like below:
Which is working perfectly fine. Now I want to make the script with simple bash script without using "expect" as like below:
But this script still ask me the password . Can anyone please help in solving this issue.
I was using the script to move the file from my server to external server using "expect" , but my production server is not having the "expect" library present and network team is not allowing to configure it.
My SFTP script was like below:
#!/usr/bin/expect
set timeout -1
if { $argc != 6 } {
puts "Usage $argv0 host user pass cd lcd file "
exit 1
}
set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set cd [lindex $argv 3]
set lcd [lindex $argv 4]
set file [lindex $argv 5]
spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host
expect *assword:
send "$pass\r"
expect sftp>
send "cd $cd\r"
expect sftp>
send "lcd $lcd\r"
expect sftp>
send "put $file\r"
send "exit\r"
expect eof
Which is working perfectly fine. Now I want to make the script with simple bash script without using "expect" as like below:
#!/bin/sh
host="$1"
user="$2"
pass="$3"
cd="$4"
lcd="$5"
file="$6"
sftp -b ${user}@${host}
${pass} << EOF
cd ${cd}
lcd ${lcd}
put ${file}
EOF
echo "end sftp"
exit
But this script still ask me the password . Can anyone please help in solving this issue.
I would setup ssh keys instead of using a password.
ASKER
I am calling this script from Oracle where one of my table is having the username , host , password etc .. so , can you please let me know how i can setup.
ASKER
The only option we do have using the password , cannot setup SSH
-b is batch mode SFTP - you cannot supply a password in that mode. From the man page:
Since it lacks user interaction it should be used in conjunction with non-interactive authentication.
ASKER
so what are the other options that we can make this happen.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks , we used expect as per my initial script. But using SFTP password passing through parameter using shell script is still open.