* Write to a file on server * @param {String|ArrayBuffer} content * @param {String} remotefile
(content, remotefile)
| 167 | * @param {String} remotefile |
| 168 | */ |
| 169 | writeFile(content, remotefile) { |
| 170 | const filename = remotefile || this.#path; |
| 171 | const localFilename = this.#getLocalname(filename); |
| 172 | return new Promise((resolve, reject) => { |
| 173 | sftp.isConnected((connectionID) => { |
| 174 | (async () => { |
| 175 | try { |
| 176 | if (this.#notConnected(connectionID)) { |
| 177 | await this.connect(); |
| 178 | } |
| 179 | |
| 180 | await internalFs.writeFile(localFilename, content, true, false); |
| 181 | const remoteFile = this.#safeName(filename); |
| 182 | sftp.putFile(remoteFile, localFilename, resolve, reject); |
| 183 | } catch (err) { |
| 184 | reject(err); |
| 185 | } |
| 186 | })(); |
| 187 | }, reject); |
| 188 | }); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Read the file from server |
no test coverage detected