Link to home
Start Free TrialLog in
Avatar of navolutions
navolutionsFlag for United States of America

asked on

PHP fopen ssh2

I am trying to open a file via fopen using ssh2 for sftp I referenced the page http://php.net/manual/en/function.ssh2-sftp.php and coded my stuff how it needed to be. Other ssh2 functions work fine but no fopen.... why not? It gives me the error
<b>Warning</b>:  fopen(ssh2.sftp://Resource id #116public_html/mesa-electricians.com/dxq_nft.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Operation now in progress in <b>/home/navolutions/public_html/library/remote_access.php</b> on line <b>606</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/home/navolutions/public_html/library/remote_access.php</b> on line <b>607</b><br />

<br />
<b>Warning</b>:  fclose(): supplied argument is not a valid stream resource in <b>/home/navolutions/public_html/library/remote_access.php</b> on line <b>608</b><br />

$connection = ssh2_connect( $this->m_ftpHost );
				if( ssh2_auth_password( $connection, $this->m_ftpUser, $this->m_ftpPassword ) ){
					$this->m_ftpConnection = ssh2_sftp( $connection );
					$this->m_loggedIn = true;
				}
....
$sftp = $this->m_ftpConnection;
				$fileStream = fopen( "ssh2.sftp://$sftp$this->m_sitePlaza/$fileLocation", "wb" );
				fwrite( $fileStream, $fileData );
				fclose( $fileStream );

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Well, the error messages show line numbers in excess of 600 yet the code snippet is only ten lines, so it would be hard to guess what else might be going on there.

Can you please make an isolated test case for us, then post the entire code and the error messages so we can see the correct line numbers?  Thanks and regards, ~Ray
Avatar of lytham
lytham

You might have better luck with phpseclib's Net_SFTP:

http://phpseclib.sourceforge.net/

Personally, I think its API is a lot more intuitive than PECL's ssh2 extension.  It's faster, as well, per this:

http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/#comment_3759
Avatar of navolutions

ASKER

Yes there is a lot going on but the lines I gave are well enough isolated to prove that what is stated at php.net is not working, and I was wonder if I was doing something wrong but it does not appear so, as far as further isolation fine here is the new error.


Warning: fopen() [function.fopen]: Unable to open ssh2.sftp://Resource id #3/test.txt on remote host in /home/navolutions/public_html/test.php on line 7

Warning: fopen(ssh2.sftp://Resource id #3/test.txt) [function.fopen]: failed to open stream: Permission denied in /home/navolutions/public_html/test.php on line 7

Warning: fwrite(): supplied argument is not a valid stream resource in /home/navolutions/public_html/test.php on line 8

Warning: fclose(): supplied argument is not a valid stream resource in /home/navolutions/public_html/test.php on line 9

and the code to go along with it
<?php 

$connection = ssh2_connect( "[NOT DISPLAYED FOR SECURITY]" );
if( ssh2_auth_password( $connection, "[NOT DISPLAYED FOR SECURITY]", "[NOT DISPLAYED FOR SECURITY]" ) ){
	$sftp = ssh2_sftp( $connection );
	$fileData = "Hello World\n";
    $fileStream = fopen( "ssh2.sftp://$sftp/test.txt", "wb" );
	fwrite( $fileStream, $fileData );
	fclose( $fileStream );
}

?>

Open in new window

It took me some time to get ssh2lib working with php could you offer some instruction as far as where I can get a API reference and guide on installing or phpize'ing the phpseclib
ASKER CERTIFIED SOLUTION
Avatar of lytham
lytham

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there a guide on installing that package on a cent os server?
Doing the research on installing the api and php object could require a great deal on research, so unless I can get a guide I will be force to accept the solution on a C grade
No guide but it was not to hard to install