Re: [Ssh-sftp-perl-users] Net::sftp
Brought to you by:
dbrobins
From: Rob V. <rob...@br...> - 2005-10-06 06:42:46
|
Here's something I use to set u connections, I assume you are capable of using public/private key logins with ssh on the command line, make sure iddsa points to the private key you use for the user to log in remotly. #!/usr/bin/perl # my default enforce neat code blok use warnings; use strict; use diagnostics; # ok diagnostics does not enforce neat code but # it does assist me to figure out where I made my stupid typo that # breaks the code and explains what kind of stupid typo I made # and the fact that I'm to lazy to think about it myself use Net::SSH::Perl; use Net::SFTP; # 0 =3D debug off 1 =3D debug on my $debug=3D=C2=A81"; my $host=3D"myhost.something.com"; my $out; my $err; my $exit; my %ssh_args =3D ( protocol =3D> "2", identity_file =3D> "$iddsafile", compression =3D> "1", debug =3D> $debug, interactive =3D> "false", ); my %sftp_args =3D ( user =3D> "mylogin", debug =3D> $debug, ssh_args =3D> \%ssh_args, #<-magic line for key-exchange ); # the line with the reference to the %ssh_args imports the settings you # need to point sftp to the keys needed for key authentication # set up ssh connection my $ssh =3D Net::SSH::Perl->new($host, %ssh_args); # set up sftp connection my $sftp =3D Net::SFTP->new($host, %sftp_args); # sending a command to $ssh session ($out, $err, $exit) =3D $ssh->cmd("ls"); # print any output if any print "STDOUT $out\n" if ($out); print "STDERR $err\n" if ($err); print "EXIT $exit\n" if ($exit); # sending a file with $sftp ($out, $err, $exit) =3D sftp->put("filesource", "filedestination"); # print any output if any print "STDOUT $out\n" if ($out); print "STDERR $err\n" if ($err); print "EXIT $exit\n" if ($exit); # end of code Ofcourse this barely covers it, but it should get you started Oh btw .... It takes Net::SSH::Perl so long to set up a connection overhere that I sometimes get timeouts from the other machine cause it's tired of waiting. Regards Rob Op wo, 05-10-2005 te 20:07 -0400, schreef David M. Funk: > Folks, >=20 >=20 > I guess I'll live with the 4+ minute wait for key-exchanges. >=20 > How do I authenticate without sending a password using Net::sftp >=20 > Any one have some sample code and good explanations that would be > great. >=20 > Thanks,=20 > David M. Funk=20 > President/CEO=20 > =20 > Tivoli Certified Enterprise Consultant=20 > Specializing in Network and Systems Management Solutions >=20 > Trinity Solutions =20 > 604 Cassandra Dr. =20 > Cranberry Twp., PA 16066=20 > =20 > Phone: 724-316-0721 =20 > Fax: 724-772-7889 =20 > email: mf...@tr...=20 > http://www.trinitysol.net >=20 >=20 >=20 >=20 > =20 >=20 |