Solved

Can I use an input file for username and password for sftp ?

Posted on 2011-03-22
5
253 Views
Last Modified: 2012-05-11
Can I use an input file for username and password for sftp much like I would for ftp.  I know I can use the Net SFTP mod, I need to know if unix sftp can read the username and password from a paramarter file
0
Comment
Question by:MatthewF
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:koppcha
ID: 35191465

This may not be what you are looking for.. These are options i could think of.

1> You can use public key authentication which doesn't require user/password authentication.
2> use expect if you have it available
3> use NET::SFTP you do the job and call it from shell script.

#!/usr/bin/expect
 
spawn sftp username@host
expect "assword:"
send "your_password\n"
expect "sftp>"
send "your command here\n"
expect "sftp>"
send "quit\n"

Open in new window

0
 

Author Comment

by:MatthewF
ID: 35192021
I was hoping to read from a paramater file from a perl script
0
 
LVL 8

Accepted Solution

by:
koppcha earned 500 total points
ID: 35192103
How about this ?


 
use Net::SFTP;
my %parameters;

open ( my $INP, "<", "config.txt" );
while( <$INP> ) {
my ( $key, $value ) = split/:/;
$parameters { $key } = $value;
}

my $sftp = Net::SFTP->new($host, %parameters);

Open in new window


config.txt
user: ABC
password: XXXX

Open in new window

0
 

Author Comment

by:MatthewF
ID: 35192392
I need o do it with out any perl modules.
0
 
LVL 8

Expert Comment

by:koppcha
ID: 35194110
If that is the case use perl and build expect script in the above email and run it from perl with system command.
If you have expect( /usr/bin/expect ) i think you could do it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now