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:


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

Open in new window

Which is working perfectly fine. Now I want to make the script with simple bash script without using "expect" as like below:



sftp -b ${user}@${host}
${pass} << EOF

cd ${cd}
lcd ${lcd} 
put ${file}
echo "end sftp"

Open in new window

But this script still ask me the password . Can anyone please help in solving this issue.
LVL 17
Swadhin Ray Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
I would setup ssh keys instead of using a password.
Swadhin Ray Author Commented:
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.
Swadhin Ray Author Commented:
The only option we do have using the password , cannot setup SSH
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Gerwin Jansen, EE MVETopic Advisor Commented:
-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.
Swadhin Ray Author Commented:
so what are the other options that we can make this happen.
Gerwin Jansen, EE MVETopic Advisor Commented:
The options that I see are:
- install expect
- use ssh keys
- use ftp instead (not secure)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Swadhin Ray Author Commented:
Thanks , we used expect as per my initial script.  But using SFTP password passing through parameter using shell script is still open.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.