diff --git a/src/SFTPconnection.php b/src/SFTPconnection.php index 731e932..e65bd41 100644 --- a/src/SFTPconnection.php +++ b/src/SFTPconnection.php @@ -118,12 +118,23 @@ class SFTPConnection public function receiveFile($remote_file, $local_file) { $sftp = $this->sftp; - $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'r'); - if (! $stream) + $remote_stream = @fopen("ssh2.sftp://$sftp$remote_file", 'rb'); + if (! $remote_stream) throw new Exception("Could not open SFTP file for reading: $remote_file"); - $contents = fread($stream, filesize("ssh2.sftp://$sftp$remote_file")); - file_put_contents($local_file, $contents); - @fclose($stream); + + $local_stream = @fopen($local_file, 'wb'); + if (! $local_stream) { + @fclose($remote_stream); + throw new Exception("Could not open local file for writing: $local_file"); + } + + $copied = @stream_copy_to_stream($remote_stream, $local_stream); + @fclose($local_stream); + @fclose($remote_stream); + + if ($copied === false) { + throw new Exception("Could not receive data from file: $remote_file."); + } } public function statFile($remote_file) diff --git a/src/SFTPsync.php b/src/SFTPsync.php index ae2c3b4..42fb8c6 100644 --- a/src/SFTPsync.php +++ b/src/SFTPsync.php @@ -988,7 +988,7 @@ function getStatusMeta(string $status): array 'MKDIR' => ['icon' => '📁', 'color' => '36'], 'RMDIR' => ['icon' => '🧹', 'color' => '35'], 'UPLOAD' => ['icon' => '⬆️', 'color' => '32'], - 'DOWNLOAD' => ['icon' => '⬇️', 'color' => '34'], + 'DOWNLOAD' => ['icon' => '⬇️', 'color' => '36'], 'DELETE' => ['icon' => '🗑️', 'color' => '31'], 'SKIP' => ['icon' => '⏭️', 'color' => '33'], 'ERROR' => ['icon' => '❌', 'color' => '91'],