thephpleague / flysystem-sftp

[READ-ONLY SUBSPLIT] Flysystem Adapter for SFTP
309 stars 95 forks source link

write stream results in a zero byte file #22

Open phuzzl opened 8 years ago

phuzzl commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

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

radonthetyrant commented 7 years ago

@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 commented 7 years ago

@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.