php - Having trouble using phpseclib to ssh into a server -


this code upload.php. files in htdocs directory of mamp. can go url http://localhost:8888/webpage.html assuming mamp working should. code upload.php.

<?php      set_include_path(get_include_path() . path_separator . 'phpseclib');     include('net/sftp.php');     include('net/ssh2.php');     //send file via sftp server     echo "begin";      echo "now connecting...";      $connection = ssh2_connect('servername.com', 22); //server redacted     echo "server made\n";     ssh2_auth_password($connection, 'username', 'password'); //username , password redacted     echo "connected successfuly\n";      echo $ssh->exec('pwd');     echo $ssh->exec('ls -la'); ?> 

when submit form , gets redirected upload.php, upload.php displays text saying

begin connecting...

so i'm assuming it's not getting past line

$connection = ssh2_connect('servername.com', 22); //server redacted

but can't figure out why.

i using mac. can ssh server , scp files via terminal using ssh username@servername.com , scp ./filename.txt username@servername.com:~/test/. , prompts me password.

maybe have wrong server name? have idea why it's not getting past line?

it's you're mixing phpseclib api , libssh2 api. $ssh variable being defined? set result of ssh2_connect $connection later use $ssh has never been defined.

anyway, try this:

<?php      set_include_path(get_include_path() . path_separator . 'phpseclib');     include('net/sftp.php');     include('net/ssh2.php');     //send file via sftp server     echo "begin";      echo "now connecting...";      $ssh = new net_ssh2('servername.com', 22); //server redacted     echo "server made\n";     $ssh->login('username', 'password'); //username , password redacted     echo "connected successfuly\n";      echo $ssh->exec('pwd');     echo $ssh->exec('ls -la'); ?> 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -