[Ssh-sftp-perl-users] Need help using passphrase with key pairs in Net::SFTP::Foreign
Brought to you by:
dbrobins
From: Russ B. <us...@gm...> - 2010-10-27 15:17:54
|
I have Net::SFTP::Foreign working fine when my key pairs have an empty passphrase. But I have been directed to no longer use key pairs that are not protected by a passphrase. In the code below I successfully use "Expect" to pass the passphrase, complete the login and even list the contents of the remote directory. But I can not then get Net::SFTP::Foreign to to utilize the connection that Expect has established ($conn). Documentation implies that transport => $conn should do the trick but it is not working in the example below. Any help will be gratefully appreciated. Note that I am using Net::SFTP::Foreign to control the Tectia ssh client, which is installed at /opt/tectia/bin/sshg3. I have no trouble controlling sshg3 except when the key pair has a non-empty passphrase. #!/usr/bin/perl use Net::SFTP::Foreign; use Expect; $Net::SFTP::Foreign = -1; my $tectia_ssh_client = "/opt/tectia/bin/sshg3"; my %feed_server; $feed_server{server} = "server01"; $feed_server{directory} = "/export/home/tuser"; my @sshargs = ('-v'); my $passphrase = "some secret group of words"; my $timeout = 20; my $delay =120; my $user = "tuser"; my $host = "server01"; my @pattern = "Passphrase for the private key:"; my $logfile = "/export/home/tuser/mylog.txt"; $Expect::Exp_Internal = 1; my $conn = Expect->new; $conn->raw_pty(1); $conn->log_stdout(1); $conn->log_file($logfile); $conn->spawn("$tectia_ssh_client $user\@$host") or die "spawn command failed"; $conn->expect($timeout, @pattern); $conn->send("$passphrase\n"); $conn->expect($timeout, "bash"); $conn->send("ls -l\n"); $conn->expect($delay, "bash"); ### === this is where things stop working ====== my $sftp = Net::SFTP::Foreign->new(transport => $conn); if (($sftp->error) || ($sftp->status)) { print "\n"; print "transport did not connect! $0\n"; print "sftp error: ".$sftp->error."\n"; print "sftp status: ".$sftp->status."\n"; } else { print "Got a connection without errors\n"; } eval { $files_in_directory = $sftp->ls("$feed_server{directory}"); }; if (($@) || ($sftp->error)) { print "sftp--> error: ".$sftp->error."\n"; print "\n"; print "Directory Listing Problem on host: $feed_server{server} $0\n"; print "Directory = $feed_server{directory}\n"; print "ERROR = $@\n"; } else { print "File in directorty: \n"; foreach (@$files_in_directory) { $longlist = $_->{longname}; $shortname = $_->{filename}; print $longlist; } } |