How to use ssh2-sftp-client - 5 common examples

To help you get started, we’ve selected a few ssh2-sftp-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / imports / plugins / included / csv-connector / server / methods.js View on Github external
async "csvConnector/sftpTestForImportAndExport"() {
    // must have core permissions
    if (!Reaction.hasPermission("core")) {
      throw new Meteor.Error("access-denied", "Access Denied");
    }
    const pkg = Packages.findOne({ name: "connector-settings-sftp" });
    const { settings: { ipAddress, port, username, password } } = pkg || {};
    const sftpClient = new Client();
    return new Promise((resolve, reject) => {
      sftpClient.connect({
        host: ipAddress,
        port: `${port}`,
        username,
        password
      }).then(() => resolve(true)).catch((error) => reject(error));
    });
  },
github getgridea / gridea / src / server / plugins / deploys / sftp.ts View on Github external
async remoteDetect() {
    const result = {
      success: true,
      message: '',
    }

    const client = new SftpClient()

    const { setting } = this.db

    const connectConfig: sftpConnectConfig = {
      host: setting.server,
      port: Number(setting.port),
      username: setting.username,
    }

    if (setting.privateKey) {
      try {
        connectConfig.privateKey = fse.readFileSync(setting.privateKey)
      } catch (e) {
        console.error('SFTP Test Remote Error: ', e.message)
        result.success = false
        result.message = e.message
github reactioncommerce / reaction / imports / plugins / included / csv-connector / server / no-meteor / processJobItem.js View on Github external
async function saveExportFileToSFTP(filePath, csvString) {
  const sftpPkg = await Packages.findOne({ name: "connector-settings-sftp" });
  const { settings: { ipAddress, port, username, password } } = sftpPkg;
  const readStream = new Readable();
  readStream.push(csvString);
  readStream.push(null);
  const sftpClient = new SFTPClient();
  return new Promise((resolve, reject) => {
    sftpClient.connect({
      host: ipAddress,
      port,
      username,
      password
    }).then(() => sftpClient.put(readStream, filePath)).catch((error) => reject(error));
  });
}
github reactioncommerce / reaction / imports / plugins / included / csv-connector / server / no-meteor / processJobItem.js View on Github external
data = await new Promise((resolve, reject) => {
        S3Config.getObject(s3Params).send((error, { Body }) => {
          if (error) {
            reject(error);
          }
          resolve(Body);
        });
      });
    } catch (error) {
      Logger.error(error);
    }
  } else {
    const sftpPkg = await Packages.findOne({ name: "connector-settings-sftp" });
    const { settings: { ipAddress, port, username, password } } = sftpPkg;

    const sftpClient = new SFTPClient();
    try {
      await sftpClient.connect({
        host: ipAddress,
        port,
        username,
        password
      });
    } catch (error) {
      Logger.error(error);
    }

    try {
      readStream = await sftpClient.get(sftpImportFilePath);
      data = await new Promise((resolve) => {
        readStream.on("data", (csvData) => {
          resolve(csvData);
github shirshak55 / scrapper-tools / src / sftp.ts View on Github external
host,
      port,
      username,
      privatekeyPath,
      filePath,
      remoteFilePath,
    }: {
      host: string
      port: string
      privatekeyPath: string
      filePath: string
      username: string
      remoteFilePath: string
    }) => {
      try {
        let sftp = new sftpClient()
        await sftp.connect({
          host,
          port,
          username,
          privateKey: fs.readFileSync(privatekeyPath),
        })
        let sftpHandler = sftp
        try {
          await sftp.mkdir(path.dirname(remoteFilePath), true)
        } catch (e) {}
        await sftp.put(filePath, remoteFilePath)
        await sftp.end()
      } catch (e) {
        consoleMessage.error('SSH Uploader Module', e)
      }
    },

ssh2-sftp-client

ssh2 sftp client for node

Apache-2.0
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis

Popular ssh2-sftp-client functions