| 111 | } |
| 112 | |
| 113 | async upload (path: string, transfer: FileUpload): Promise<void> { |
| 114 | this.logger.info('Uploading into', path) |
| 115 | const tempPath = path + '.tabby-upload' |
| 116 | try { |
| 117 | const handle = await this.open(tempPath, russh.OPEN_WRITE | russh.OPEN_CREATE) |
| 118 | while (true) { |
| 119 | const chunk = await transfer.read() |
| 120 | if (!chunk.length) { |
| 121 | break |
| 122 | } |
| 123 | await handle.write(chunk) |
| 124 | } |
| 125 | await handle.close() |
| 126 | await this.unlink(path).catch(() => null) |
| 127 | await this.rename(tempPath, path) |
| 128 | transfer.close() |
| 129 | } catch (e) { |
| 130 | transfer.cancel() |
| 131 | this.unlink(tempPath).catch(() => null) |
| 132 | throw e |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | async download (path: string, transfer: FileDownload): Promise<void> { |
| 137 | this.logger.info('Downloading', path) |