SFTP connections via PHP

From: Date: Wed, 26 Sep 2007 01:13:50 +0000
Subject: SFTP connections via PHP
Groups: php.general 
Request: Send a blank email to php-general+get-262467@lists.php.net to get a copy of this message
Hi All, Just wondering if anyone has had any success getting a connection working with PHP via SFTP. I am running Win 2003 Server PHP Version 5.1.6 Win32 OpenSSL v0.9.8e Light is installed PECL module for SSH2 is installed The following code ----------------------------- // create connetion to remote server if (!$sftpConnection = ssh2_connect(DNCR_SERVERNAME, 22)) {
       echo 'ERROR: Server connection failed.' . "\n";
       exit;
} // check fingerprint of remote server matches what we expect $dncrFingerprint = ssh2_fingerprint($sftpConnection, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX); if ($dncrFingerprint != DNCR_FINGERPRINT && FALSE) {
       echo 'ERROR: Hostkey mismatch.' . "\n";
       exit;
} // ensure that authentication methods allowed $sshAcceptedAuthenticationMethods = ssh2_auth_none($sftpConnection,DNCR_USERNAME); echo "\n" . 'Accepted authentication methods:' . "\n"; for ($i = 0; $i < count($sshAcceptedAuthenticationMethods); $i++) echo $sshAcceptedAuthenticationMethods[$i] . "\n"; echo "\n"; $sshNegotiatedMethods = ssh2_methods_negotiated($sftpConnection); echo 'Encryption keys were negotiated using: {' . $sshNegotiatedMethods['kex'] . '}' . "\n"; echo 'Server identified using an {' . $sshNegotiatedMethods['hostkey'] . '} with '; echo 'fingerprint: ' . ssh2_fingerprint($sftpConnection) . "\n"; echo 'Client to Server packets will use methods:' . "\n"; echo 'Crypt: {' . $sshNegotiatedMethods['client_to_server']['crypt'] . '}' . "\n"; echo 'Comp: {' . $sshNegotiatedMethods['client_to_server']['comp'] . '}' . "\n"; echo 'MAC: {' . $sshNegotiatedMethods['client_to_server']['mac'] . '}' . "\n"; echo 'Server to Client packets will use methods:' . "\n"; echo 'Crypt: {' . $sshNegotiatedMethods['server_to_client']['crypt'] . '}' . "\n"; echo 'Comp: {' . $sshNegotiatedMethods['server_to_client']['comp'] . '}' . "\n"; echo 'MAC: {' . $sshNegotiatedMethods['server_to_client']['mac'] . '}' . "\n"; if (!ssh2_auth_password($sftpConnection, DNCR_USERNAME , DNCR_PASSWORD)) {
       echo 'ERROR: Cannot authenticate to remote server.' . "\n";
       exit;
} ----------------------------- produces the following result ----------------------------- Accepted authentication methods: publickey keyboard-interactive Encryption keys were negotiated using: {diffie-hellman-group14-sha1} Server identified using an {ssh-dss} with fingerprint: F4EE0910B0C6BA932908320145F87790 Client to Server packets will use methods: Crypt: {aes256-cbc} Comp: {none} MAC: {hmac-sha1} Server to Client packets will use methods: Crypt: {aes256-cbc} Comp: {none} MAC: {hmac-sha1} *Warning*: ssh2_auth_password() [function.ssh2-auth-password <http://vesd.rd.cx/phoenix/function.ssh2-auth-password>]: Authentication failed for myusername using password in *c:\Inetpub\wwwroot\VESD\phoenix\composer-stage1-wash-file-submission.php* on line *67* ERROR: Cannot authenticate to remote server. ----------------------------- I can connect to this remote server via SFTP using Filezilla so there is no firewall issues. I also did a bit of reading on the accepted authentication method of keyboard-interactive and it states that password should be allowed to be sent http://www.ssh.com/support/documentation/online/ssh/winhelp/32/overview.html Any help would be greatly appreciated. Thankyou PS: I am sorry for the double post but noone has responded to this email on the windows list so I thought I would try my luck here...

« previous php.general (#262467) next »