function getSftp (callback) { if (sftpClient) return callback(null, sftpClient) ctx.connect().ready(function () { ssh.sftp(function (err, sftp) { if (err) return callback(err) sftpClient = sftp callback(null, sftp) }) }) }
through.obj(function (file, encoding, callback) { ctx.ready(function () { ssh.sftp(function (err, sftp) { if (err) return callback(new gutil.PluginError(packageName, err)) options.autoClose = true var write = sftp.createWriteStream(filePath, options) write .on('error', function (error) { err = error }) .on('finish', function () { sftp.end() if (err) callback(err) else callback(null, file) }) if (file.isStream()) file.pipe(write) else if (file.isBuffer()) write.end(file.contents); else { err = new gutil.PluginError(packageName, 'file error!') write.end() } }) }) })
ctx.ready(function () { ssh.sftp(function (err, sftp) { if (err) return outStream.emit('error', new gutil.PluginError(packageName, err)) var read = sftp.createReadStream(filePath, options) options.base = options.base || '' read .on('data', function (chunk) { chunkSize += chunk.length chunks.push(chunk) }) .on('error', function (err) { outStream.emit('error', err) }) .on('end', function () { outStream.push(new gutil.File({ cwd: __dirname, base: __dirname, path: path.join(__dirname, options.filePath || filePath), contents: Buffer.concat(chunks, chunkSize) })) outStream.end() this.close() }) .on('close', function () { sftp.end() }) }) })
disconnect() { return super.disconnect().then(() => this.client.end()); }
constructor(options) { super(); let client = new SshClient(), connectOptions = Object.assign({ host: '127.0.0.1', port: 10022 }, options); this.client = client; this.host = connectOptions.host; this.port = connectOptions.port; client.on('ready', () => { client.shell(false, (err, stream) => { if(err) super.emit('error', err); else super.streamSetup(stream, stream); }); }); client.connect(connectOptions); }
conn.on('ready', function() { Object.keys(server).forEach(function(k){ if(conn[k]){ conn.connect(server); conn.on('error',function(stderr){ if(stderr) debug(''+stderr); done(stderr, null); var superEnd = conn.end; conn.end = function(){ debug('end connection %s', conn.pendingStreams.length); conn.pendingStreams.forEach(function(stream, i){ debug('kill stream %s', i); stream.kill(conn.pendingStreams.length); }); conn.pendingStreams = []; conn.end(); }; process.on('SIGINT', sigIntSent); conn.on('close',function(){ try{ process.removeListener('SIGINT', sigIntSent); }catch(ex){} }); conn.on('end',function(){ try{
conn.on('ready', function() { conn.forwardOut(sock.remoteAddress, sock.remotePort, proxy_remote, squid_port, function(err, stream) { if (err) { conn.end() return deny() deny() }).on('close', function (err) { conn.end(); }).pipe(stream).on('error', function (err) { deny() }).on('close', function() { conn.end() }) }) }).on('error', function(err) { deny() }).connect(ssh_config) }).listen(squid_port, '::', () => { if (!proxy_ports.indexOf(squid_port) > -1) { proxy_ports.push(squid_port) } conn.on('ready', function() { conn.forwardOut(sock.remoteAddress, sock.remotePort, proxy_remote, socks_port, function(err, stream) { if (err) { conn.end() return deny() deny() }).on('close', function (err) {
describe('SSH Server', function() { it('should reject if username is not git', function(done) { var conn = new Client(); conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, TestAuthenticator.SSH_VALID = false; var conn = new Client(); conn.on('error', function(err) { err.message.should.equal('All configured authentication methods failed'); done(); }).connect({ host: '127.0.0.1', port: SSH_PORT, TestAuthenticator.SSH_VALID = true; var conn = new Client(); conn.on('ready', function(err) { done();