Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write stream results in a zero byte file #22

Open
phuzzl opened this issue Apr 21, 2016 · 6 comments
Open

write stream results in a zero byte file #22

phuzzl opened this issue Apr 21, 2016 · 6 comments

Comments

@phuzzl
Copy link

phuzzl commented Apr 21, 2016

When I try to write a stream via writeStream() it results in a zero byte file on the SFTP-Server.
With the Flysystem FTP adapter it works correctly.

        $stream = fopen($path_to_file, 'r', false, $context_i_set_somewhere);

        $storage = new Filesystem(new SftpAdapter($configuration_array_i_have_set_somewhere));

        $storage->writeStream($path_and_file_name_i_set_somewhere, $stream);

        fclose($stream);
@mpipet
Copy link

mpipet commented Jun 2, 2016

I encountered a similar issue with $stream = fopen('php://stdin', 'r') , the problem came from the underlying lib phpseclib
I made a PR (see for explanations) which could hopefully solves your problem.

@EvilLooney
Copy link

I'd like to add that this happens for remote files as well: $stream = fopen('http://path/to/file, 'rb')

I believe it has to do with with phpseclib/Net/SFTP's put function trying to get the size of the remote file with fstat but instead returning null although I am not at all an expert on streams and not quite sure how to fix this.

@bobmulder
Copy link

Hi all!

Is there any progress in this issue? Unfortunately I am facing this issue as well. I can confirm it's really SFTP (or the underlying lib phpseclib) because the Local adapter and Dropbox adapter are working.

Also, I see the suggestion of the PR are commited to the code base, however the issue isn't solved...

I would like to hear from you!

Greetz,

Bob

@wizonesolutions
Copy link

For those who don't actually have to use writeStream(), write() works fine.

@radonthetyrant
Copy link

@wizonesolutions I just encountered this issue myself trying to download a huge file from a linux sftp box to a local linux filesystem. The transfer happened (the script execution was delayed during which stuff happened) but the resulting file had zero bytes.
How does write work different? Does the file get buffered in php's memory? What happens if filesize exceeds lets say 10GB?

@wizonesolutions
Copy link

@radonthetyrant that's probably the main difference and the reason that won't work for everyone. From what I can tell, phpseclib did fix the issue. Maybe this project isn't using the new version? I didn't go that deep, as I didn't really want to patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants