| 614 | } |
| 615 | |
| 616 | public void createFile(JSONArray args, CallbackContext callback) { |
| 617 | cordova |
| 618 | .getThreadPool() |
| 619 | .execute( |
| 620 | new Runnable() { |
| 621 | public void run() { |
| 622 | try { |
| 623 | String path = args.optString(0); |
| 624 | String content = args.optString(1, ""); |
| 625 | |
| 626 | if (ssh != null && sftp != null) { |
| 627 | try { |
| 628 | SftpFileAttributes attrs = sftp.stat(path); |
| 629 | if (attrs != null && attrs.isFile()) { |
| 630 | callback.error("File already exists"); |
| 631 | return; |
| 632 | } |
| 633 | } catch (SftpStatusException e) { |
| 634 | // File doesn't exist, continue with creation |
| 635 | } |
| 636 | |
| 637 | java.io.ByteArrayInputStream inputStream; |
| 638 | if (content.isEmpty()) { |
| 639 | inputStream = new java.io.ByteArrayInputStream(new byte[0]); |
| 640 | } else { |
| 641 | inputStream = new java.io.ByteArrayInputStream( |
| 642 | content.getBytes(StandardCharsets.UTF_8) |
| 643 | ); |
| 644 | } |
| 645 | sftp.put(inputStream, path); |
| 646 | callback.success(); |
| 647 | return; |
| 648 | } |
| 649 | callback.error("Not connected"); |
| 650 | } catch ( |
| 651 | SftpStatusException | SshException | TransferCancelledException e |
| 652 | ) { |
| 653 | callback.error(errMessage(e)); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | ); |
| 658 | } |
| 659 | |
| 660 | public void rename(JSONArray args, CallbackContext callback) { |
| 661 | cordova |