How to use the ssh2.SFTP_OPEN_MODE function in ssh2

To help you get started, we’ve selected a few ssh2 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 mscdex / ssh2 / examples / sftp-server-download-only.js View on Github external
var crypto = require('crypto');
var constants = require('constants');
var fs = require('fs');

var ssh2 = require('ssh2');
var OPEN_MODE = ssh2.SFTP_OPEN_MODE;
var STATUS_CODE = ssh2.SFTP_STATUS_CODE;

var allowedUser = Buffer.from('foo');
var allowedPassword = Buffer.from('bar');

new ssh2.Server({
  hostKeys: [fs.readFileSync('host.key')]
}, function(client) {
  console.log('Client connected!');

  client.on('authentication', function(ctx) {
    var user = Buffer.from(ctx.username);
    if (user.length !== allowedUser.length
        || !crypto.timingSafeEqual(user, allowedUser)) {
      return ctx.reject(['password']);
    }
github pterodactyl / daemon / src / http / sftp.js View on Github external
*/

const Fs = require('fs-extra');
const rfr = require('rfr');
const Async = require('async');
const _ = require('lodash');
const Ssh2 = require('ssh2');
const Moment = require('moment');
const Util = require('util');
const Ssh2Streams = require('ssh2-streams');
const Path = require('path');
const Randomstring = require('randomstring');
const Request = require('request');

const SftpStream = Ssh2Streams.SFTPStream;
const OPEN_MODE = Ssh2.SFTP_OPEN_MODE;
const STATUS_CODE = Ssh2.SFTP_STATUS_CODE;

const Log = rfr('src/helpers/logger.js');
const ConfigHelper = rfr('src/helpers/config.js');
const Servers = rfr('src/helpers/initialize.js').Servers;
const SFTPQueue = rfr('src/helpers/sftpqueue.js');
const Config = new ConfigHelper();

class InternalSftpServer {
    init(next) {
        Ssh2.Server({
            algorithms: { compress: Config.get('sftp.algos.compress', ['none', 'zlib']) },
            hostKeys: [
                Fs.readFileSync(Config.get('sftp.keypair.hostkey_path', './config/.sftp/id_rsa')).toString('utf8'),
            ],
        }, client => {