navolutions
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-elect ricians.co m/dxq_nft. php) [<a href='function.fopen'>func tion.fopen </a>]: failed to open stream: Operation now in progress in <b>/home/navolutions/publi c_html/lib rary/remot e_access.p hp</b> on line <b>606</b><br />
<br />
<b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>/home/navolutions/publi c_html/lib rary/remot e_access.p hp</b> on line <b>607</b><br />
<br />
<b>Warning</b>: fclose(): supplied argument is not a valid stream resource in <b>/home/navolutions/publi c_html/lib rary/remot e_access.p hp</b> on line <b>608</b><br />
<b>Warning</b>: fopen(ssh2.sftp://Resource id #116public_html/mesa-elect
<br />
<b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>/home/navolutions/publi
<br />
<b>Warning</b>: fclose(): supplied argument is not a valid stream resource in <b>/home/navolutions/publi
$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 );
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
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
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_h tml/test.p hp on line 7
Warning: fopen(ssh2.sftp://Resource id #3/test.txt) [function.fopen]: failed to open stream: Permission denied in /home/navolutions/public_h tml/test.p hp on line 7
Warning: fwrite(): supplied argument is not a valid stream resource in /home/navolutions/public_h tml/test.p hp on line 8
Warning: fclose(): supplied argument is not a valid stream resource in /home/navolutions/public_h tml/test.p hp on line 9
and the code to go along with it
Warning: fopen() [function.fopen]: Unable to open ssh2.sftp://Resource id #3/test.txt on remote host in /home/navolutions/public_h
Warning: fopen(ssh2.sftp://Resource id #3/test.txt) [function.fopen]: failed to open stream: Permission denied in /home/navolutions/public_h
Warning: fwrite(): supplied argument is not a valid stream resource in /home/navolutions/public_h
Warning: fclose(): supplied argument is not a valid stream resource in /home/navolutions/public_h
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 );
}
?>
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there a guide on installing that package on a cent os server?
ASKER
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
ASKER
No guide but it was not to hard to install
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