.htaccess
1 year ago
ChunkedDownload.php
1 year ago
ChunkedUpload.php
1 year ago
DirIterator.php
1 year ago
SFTP.php
1 year ago
index.html
1 year ago
web.config
1 year ago
ChunkedUpload.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Destination\Vendors\SFTP; |
| 4 | |
| 5 | use JetBackup\Destination\Integration\DestinationChunkedUpload; |
| 6 | use JetBackup\Exception\IOException; |
| 7 | use phpseclib3\Net\SFTP as lSFTP; |
| 8 | use JetBackup\Web\File\FileChunk; |
| 9 | |
| 10 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 11 | |
| 12 | class ChunkedUpload implements DestinationChunkedUpload { |
| 13 | |
| 14 | private SFTP $_connection; |
| 15 | private string $_destination; |
| 16 | private \stdClass $_data; |
| 17 | |
| 18 | public function __construct(SFTP $connection, $destination) { |
| 19 | $this->_connection = $connection; |
| 20 | $this->_destination = $destination; |
| 21 | $this->_data = new \stdClass(); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @return object |
| 26 | */ |
| 27 | public function prepare():object { return new \stdClass(); } |
| 28 | public function setData(object $data):void {} |
| 29 | |
| 30 | /** |
| 31 | * @return int |
| 32 | * @throws IOException |
| 33 | */ |
| 34 | public function getOffset():int { |
| 35 | return $this->_connection->retries(function() { |
| 36 | $stat = $this->_connection->getConnection()->stat($this->_destination); |
| 37 | return $stat ? $stat['size'] : 0; |
| 38 | }, "Failed fetching upload offset"); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param FileChunk $chunk |
| 43 | * |
| 44 | * @return void |
| 45 | * @throws IOException |
| 46 | */ |
| 47 | public function upload(FileChunk $chunk):void { |
| 48 | while($data = $chunk->read(1024 * 1024)) { |
| 49 | $this->_connection->retries(function() use ($chunk, $data) { |
| 50 | $offset = $chunk->getFile()->tell(); |
| 51 | $this->_connection->getConnection()->put($this->_destination, $data, lSFTP::SOURCE_STRING, $offset); |
| 52 | }, "Failed uploading chunk"); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return void |
| 58 | */ |
| 59 | public function finalize():void {} |
| 60 | |
| 61 | /** |
| 62 | * @inheritDoc |
| 63 | */ |
| 64 | public function getChunkSize(): ?int { |
| 65 | return null; |
| 66 | } |
| 67 | } |