2

In PHP, I cannot even get the SFTP connection to work. I have tried to use the native SFTP functionality (ssh_connect), and it fails to connect. I have also tried to use phpseclib, but it fails as well. Neither of my aforementioned attempts have provided much in the way of log info.

The native code:

if (!function_exists('ssh2_connect')) { 
    echo "dll not loaded properly"; //never see this, so I know it works
    return false;
}
$connection = ssh2_connect('sftp.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);

phpseclib library code:

include('Net/SFTP.php');

$sftp = new Net_SFTP('sftp.example.com');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

I have also tried to track all of the transactions via Fiddler to see if I at least see a connection being made, and I do see an error in the browser (below) that from googling may mean that a connection was made to the server, but no responses.

[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 17139 bytes. 

Why am I able to connect to the URL with the username and password via FIleZilla, but not from within php? Do I need some other DLLs in PHP's /ext folder (e.g. php_openssl.dll, etc.)?

Thanks, Sean

Sean Charles
  • 267
  • 3
  • 18
  • i use phpseclib for debugging: add `print_r($sftp->getSFTPErrors());` before the exit –  Jul 12 '15 at 02:29
  • I had not tried getSFTPErrors(), but I had been trying to display $sftp->getLog(). I tried the getSFTPErrors() and just like the getLog(), nothing is returned. – Sean Charles Jul 12 '15 at 04:21
  • full regular error checking on? –  Jul 12 '15 at 04:24
  • Good question. I'm not sure. At the top of my function, I have this: define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX); // NET_SFTP_LOG_COMPLEX or NET_SFTP_LOG_SIMPLE – Sean Charles Jul 12 '15 at 04:27
  • i was think along the lines of: `ini_set('display_errors', 'On'); ini_set('html_errors', 0); error_reporting(-1);` –  Jul 12 '15 at 20:44
  • Thanks @Dagon. I at least received some error messages now. Although I'm not exactly sure how to fix them. **Unexpected PHP error [No compatible server to client encryption algorithms found] severity [1024] in [C:\dev\php\workspace\phpseclib\Net\SSH2.php line 1266]** Any ideas on how to enable the appropriate encryption algorithm? – Sean Charles Jul 14 '15 at 01:33
  • i believe that means the files are not included properly. –  Jul 14 '15 at 01:45
  • Yeah, so far that is what my google research has found as well. Specifically there have been reports that the /Crypt/RC4.php file is not included properly, but I have included it, and I've got the same issue. I'll keep digging and see if I can't come back and give a fix for future generations. – Sean Charles Jul 14 '15 at 02:09
  • @Dagon, I'm using PHP version 5.3.3, and from what I can tell of phpseclib's documentation I should be fine to use the library as-is. So I've included some of the library files at the top, much like: **require_once($GLOBALS['codedir'] . "/phpseclib/Crypt/RC4.php");** Should I be included the files in some other way? – Sean Charles Jul 14 '15 at 02:16
  • try adding `set_include_pat` before include. mine: `set_include_path(get_include_path() . PATH_SEPARATOR . '/var/virtual/customers/XXX/html/update/phpseclib'); include ('/var/virtual/customers/XXX/html/update/phpseclib/Net/SFTP.php');` –  Jul 14 '15 at 02:33
  • Awesome, I was able to get it to connect, and then upload a file. I'm not sure how to give you credit for your combined answers (let me know if there is a way), but thanks for all the help!! – Sean Charles Jul 14 '15 at 03:36
  • glad it worked out, just luck i have used that library for a project - you could write up an answer (even a brief one) for any one else searching –  Jul 14 '15 at 03:41
  • @Dagon I am having this same problem. But setting the path of the include files is not working for me. So can you please guide me? – Anandharaman Buvaneswaran Dec 31 '16 at 20:09

0 Answers0