|
Posted by "M. Sokolewicz" on 06/20/05 01:01
Lowell Allen wrote:
> On Jun 19, 2005, at 12:37 PM, M. Sokolewicz wrote:
>
>> Lowell Allen wrote:
>>
>>> I need to use SFTP to send text files and binary files from one
>>> server to another, but I'm unable to use fopen on the remote server,
>>> and if I send with ssh2_scp_send the files are truncated. I'm
>>> assuming the libssh2-PECL/ssh2 installation isn't the problem
>>> because I'm able to connect using ssh2_auth_password, create a
>>> directory on the remote server with ssh2_sftp_mkdir, and copy files
>>> with ssh2_sftp_send and ssh2_sftp_recv (even though ssh2_sftp_send
>>> truncates files).
>>> When I try to use fopen, I get this error message:
>>> Warning: fopen(): Unable to open ssh2.sftp://Resource id
>>> #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt on
>>> remote host in /home/user/public_html/cms/sftp_test.php on line 79
>>> Warning: fopen(ssh2.sftp://Resource id
>>> #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt):
>>> failed to open stream: Resource temporarily unavailable in
>>> /home/user/public_html/cms/sftp_test.php on line 79
>>> Here's line 79 of sftp_test.php:
>>> $stream =
>>> fopen("ssh2.sftp://$sftp/whatever.com:22/home/whatever/public_html/
>>> flamingo/".$filename, "wt")
>>> I've read "Secure Communications with PHP and SSH" in the February
>>> PHP Architect. That's what prompted me to try PECL/ssh2, but now I'm
>>> stuck. Anybody successfully using fopen with SFTP or anybody using
>>> ssh2_sftp_send without getting truncated files?
>>
>>
>> First of all, posting this once is enough. Second of all, I think the
>> problem here is actually a lot easier than it would look at first
>> glance :)
>>
>> I noticed the following error:
>> Warning: fopen(ssh2.sftp://Resource id #10/[...]): [...]
>>
>> Now, what you see here is that you suddenly have a
>> "ssh2.sftp://Resource id #10". This is probably not the domain name
>> you're trying to connect to, now is it? :) That string typically
>> appears only when you cast a resource to a string (eg. a
>> mysql-connection, a stream, or whatever). So, looking at line 79, I
>> would guess that $sftp isn't a string which tells fopen where to find
>> the file to open, but instead is a resource which should not be there
>> at all.
>
>
> Thanks for your reply. I apologize for the duplication. I posted until
> I saw it show up, and I've only seen it once -- probably my gmail
> account marking as spam, which I don't see because I retrieve as a POP
> account with Thunderbird. I unsubscribed and subscribed with a
> different email address and posted again.
>
> Here's where $sftp is coming from:
>
> $connection = ssh2_connect("copy-design.com", 22);
> $sftp = ssh2_sftp($connection);
>
> And from the examples I've seen, the correct syntax for opening a
> handle is what I use on line 79:
>
> $stream =
> fopen("ssh2.sftp://$sftp/whatever.com:22/home/whatever/public_html/
> flamingo/".$filename, "wt")
>
> The info at <http://us4.php.net/manual/en/function.ssh2-sftp.php> says
> that ssh_sftp() "returns an SSH2 SFTP resource", which is what I
> figured "Resource id #10" is referring to. From the manual example for
> ssh_sftp:
>
> $connection = ssh2_connect('shell.example.com', 22);
> ssh2_auth_password($connection, 'username', 'password');
> $sftp = ssh2_sftp($connection);
> $stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
>
> Perhaps I'm being as inept with this code as I seem to be with my
> email, but if the domain is "whatever.com", and the file is located at
> "/home/whatever/public_html/flamingo/", and the file name is
> "test.txt", and I want to open the file (which doesn't exist yet) for
> writing, what should I use if not
> 'fopen("ssh2.sftp://$sftp/whatever.com:22/home/whatever/public_html/
> flamingo/test.txt", "wt")'?
>
> --
> Lowell Allen
hmm... yes, I see your point, and by looking at the docs I see you were
correct. However, in that case, I think the docs would be incorrect. I
mean, why would a Resource, cast to a string, be sent as a path??? :|
Navigation:
[Reply to this message]
|