flysystem-sftp icon indicating copy to clipboard operation
flysystem-sftp copied to clipboard

write stream results in a zero byte file

Open phuzzl opened this issue 8 years ago • 6 comments

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);

phuzzl avatar Apr 21 '16 09:04 phuzzl

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.

mpipet avatar Jun 02 '16 14:06 mpipet

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.

EvilLooney avatar Sep 23 '16 15:09 EvilLooney

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

bobmulder avatar Nov 30 '16 12:11 bobmulder

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

wizonesolutions avatar Mar 22 '17 23:03 wizonesolutions

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

radonthetyrant avatar Mar 23 '17 16:03 radonthetyrant

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

wizonesolutions avatar Mar 23 '17 19:03 wizonesolutions