[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3017
  • Last Modified:

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

0
navolutions
Asked:
navolutions
  • 5
  • 2
1 Solution
 
Ray PaseurCommented:
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
0
 
lythamCommented:
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
0
 
navolutionsAuthor Commented:
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

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
navolutionsAuthor Commented:
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
0
 
navolutionsAuthor Commented:
Is there a guide on installing that package on a cent os server?
0
 
navolutionsAuthor Commented:
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
0
 
navolutionsAuthor Commented:
No guide but it was not to hard to install
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now