Solved

SFTP - passing a password from within a script

Posted on 2002-07-01
7
24,208 Views
Last Modified: 2010-08-05
I just about have everything working with SFTP.  I tested SFTP using a batch file to pass it the commands and it works great.  The problem I have though is it prompts me to put a password before it starts reading the file and processing the commands.

Here is the syntax I use from the command line:

sftp -b /path/genPluginBatch webuser@webhost

I tried putting the password as the first line in the batch file, genPluginBatch, but it sees this as a bad command.  Any idea how I would pass the password from within a script?

Just so you know I also tried the following from within the script:

sftp wsadmin@uscscdev7 webuser@webhost <<EOF
<password>
cd /opt/WebSphere/AppServer/config
put plugin-cfg.xml
bye
EOF


Thanks,

Lisa
0
Comment
Question by:lphillips120898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 7123310
You can try the -n option:

sftp -n wsadmin@uscscdev7 webuser@webhost <<EOF
...etc...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 150 total points
ID: 7124044
sh does not allow to read password from STDIN (batch file, here document, or whatever) for obvious reason.
You need to setup sh with a RSA or DSA key which has a blank password
AFAIK sftp has no -i option to specify the key-file, so you're forced to use the default ones, ~/.ssh/identity for example.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7124046
oops, typo:
please substitute all words sh by ssh
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:PeterMac
ID: 7126856
Havn't tried with SFTP, but following works with most FTP systems. Needs -n on command line to allow manual login. Insert at start of batch file :-

user "USERNAME"
"PASSWD"

Alternatively should be possible to setup SFTP to run with "anonymous" access permitted. Will not then require entry of username, password at all.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7127074
SFTP is a very different beast from FTP.  Ahoffman's comments are right-on.
0
 

Expert Comment

by:SoHo
ID: 7319941
why don't you use ssh keys.
0
 

Expert Comment

by:SoHo
ID: 7319945
ahoffman already gave that answer, duh.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AIX    Volume group Auto ON/OFF question 2 146
UNIX SCP 5 95
unix in java example 9 88
Best way to split and output to csv in bash 2 81
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question