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

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
MatthewFAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
koppchaConnect With a Mentor Commented:
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
 
koppchaCommented:

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
 
MatthewFAuthor Commented:
I was hoping to read from a paramater file from a perl script
0
 
MatthewFAuthor Commented:
I need o do it with out any perl modules.
0
 
koppchaCommented:
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
All Courses

From novice to tech pro — start learning today.