Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. require_once '../lib/phpSec/bootstrap.php';
  3. require_once 'SplClassLoader.php';
  4. $classLoader = new SplClassLoader('phpSec', '../Generic/lib');
  5. $classLoader->register();
  6.  
  7.  
  8. $server = "123.456.789.012";
  9. $port = "22";
  10. $username = "xxx";
  11. $password = "xxx";
  12.  
  13. set_include_path(get_include_path() . PATH_SEPARATOR . 'c:Apachehtdocsphpseclib');
  14. define('NET_SSH2_LOGGING', 2);
  15.  
  16. include 'phpseclib/Net/SFTP.php';
  17.  
  18. define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
  19.  
  20. $sftp = new Net_SFTP($server);
  21.  
  22. // Check SFTP Connection
  23. if (!$sftp->login($username, $password))
  24. {
  25. echo 'Login Failed.';
  26.  
  27. print "</br>";
  28.  
  29. $ERR1 = $sftp->getSFTPErrors();
  30. print_r($ERR1);
  31.  
  32. print "</br>";
  33.  
  34. $ERR2 = $sftp->getErrors();
  35. print_r($ERR2);
  36. }
  37. else
  38. {
  39. echo 'Connected to SFTP.';
  40.  
  41. echo $sftp->pwd();
  42. }
  43.  
  44. ?>
  45.  
  46. try{
  47. $sftp->login($username, $password);
  48. }
  49. catch(Exception $e){
  50. echo $e->getMessage();
  51. }
  52.  
  53. <?php
  54. $connection = ssh2_connect('shell.example.com', 22);
  55. ssh2_auth_password($connection, 'username', 'password');
  56.  
  57. $sftp = ssh2_sftp($connection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement