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

Method putFile

src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java:356–407  ·  view source on GitHub ↗
(JSONArray args, CallbackContext callback)

Source from the content-addressed store, hash-verified

354 }
355
356 public void putFile(JSONArray args, CallbackContext callback) {
357 cordova
358 .getThreadPool()
359 .execute(
360 new Runnable() {
361 public void run() {
362 try {
363 String remoteFilename = args.optString(0);
364 String localFilename = args.optString(1);
365
366 if (ssh == null || sftp == null) {
367 callback.error("Not connected");
368 return;
369 }
370
371 if (remoteFilename == null || remoteFilename.isEmpty()) {
372 callback.error("Remote filename is required");
373 return;
374 }
375
376 if (localFilename == null || localFilename.isEmpty()) {
377 callback.error("Local filename is required");
378 return;
379 }
380
381 File localFile;
382 try {
383 URI uri = new URI(localFilename);
384 localFile = new File(uri);
385 } catch (URISyntaxException e) {
386 callback.error("Invalid local URI: " + errMessage(e));
387 return;
388 }
389
390 if (!localFile.exists() || !localFile.canRead()) {
391 callback.error("Local file does not exist or is not readable");
392 return;
393 }
394
395 try {
396 sftp.put(localFile.getAbsolutePath(), remoteFilename);
397 callback.success("File uploaded successfully");
398 } catch (IOException e) {
399 callback.error("Error uploading file: " + errMessage(e));
400 }
401 } catch (Exception e) {
402 callback.error(errMessage(e));
403 }
404 }
405 }
406 );
407 }
408
409 public void lsDir(JSONArray args, CallbackContext callback) {
410 cordova

Callers

nothing calls this directly

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected