Reputation: 145
I can currently connect to an SFTP server using a username/password combination:
print "Attempting connection...\n";
open( my $LFTP,'|-', "lftp -u $ftpuser,'$ftppwd' -e open -p $ftpport $ftpserver" ) or die "Cannot open lftp: $!";
print $LFTP <<"END";
ls
END
close($LFTP); # die unless lftp exit code is 0
exit 0;
How can change this code to connect to a different server using an SSH key which is encrypted with a passphrase?
This is what I've tried:
print "Attempting connection...\n";
# $ftppwd is blank now!
open( my $LFTP,'|-', "lftp -u $ftpuser,'$ftppwd' -e 'set sftp:connect-program \"ssh -a -x -i $keypath\"; open $ftpserver;'" ) or die "Cannot open lftp: $!";
print $LFTP <<"END";
ls
END
close($LFTP); # die unless lftp exit code is 0
exit 0;
The output is stuck at:
Attempting connection...
`ls' at 0 [Connecting...]
Thank you in advance for any help..
Upvotes: 0
Views: 703
Reputation: 1481
Add -u option to the open command inside -e argument and use the pass phrase as the password. You should also use url syntax to select the sftp protocol, e.g. sftp://user:phrase@server
Upvotes: 0