PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sat Oct 24, 2020 9:15 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Aug 14, 2011 12:12 am 
Forum Newbie

Joined: Sun Aug 14, 2011 12:09 am
Posts: 1
I need to set up SFTP using a public key without a password from within PHP on Ubuntu, but I can't get the script to work.

To make sure that sftp is even possible, I set it up to work from the bash prompt and it works well, so that's out of the way.

I installed the phpseclib Net_SFTP and Crypt_RSA packages following the phpseclib documentation, and below is my script. To simplify testing, the public key file "" and private key file "id_rsa" (generated when I set up sftp from the shell) reside in the same directory as my test script:


set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

$rsa = new Crypt_RSA();
//$pubKey = file_get_contents('');
$priKey = file_get_contents('id_rsa');

$sftp = new Net_SFTP('myremoteserver');
//if (!$sftp->login('myusername', $password)) {
if (!$sftp->login('myusername', $rsa)) {
exit("Login Failed\n");
echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', 'Hello, world!');


The script works if I use a string password (commented out above), but when I use the $rsa object, the script fails. I tried setting the public key (commented out above) but that fails, too.

Any thoughts on what I'm missing or doing wrong? Thanks!

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group