MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / writeFile

Method writeFile

src/fileSystem/sftp.js:169–189  ·  view source on GitHub ↗

* Write to a file on server * @param {String|ArrayBuffer} content * @param {String} remotefile

(content, remotefile)

Source from the content-addressed store, hash-verified

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

Callers 1

writeFileFunction · 0.45

Calls 6

#getLocalnameMethod · 0.95
#notConnectedMethod · 0.95
connectMethod · 0.95
#safeNameMethod · 0.95
isConnectedMethod · 0.65
putFileMethod · 0.65

Tested by

no test coverage detected