Giter Club home page Giter Club logo

gulp-ssh's Introduction

gulp-ssh

SSH and SFTP tasks for gulp

NPM version Build Status

Install

Install with npm

npm install --save-dev gulp-ssh

Example

'use strict'

var fs = require('fs');
var gulp = require('gulp')
var GulpSSH = require('gulp-ssh')

var config = {
  host: '192.168.0.21',
  port: 22,
  username: 'iojs',
  privateKey: fs.readFileSync('/Users/zensh/.ssh/id_rsa')
}


var gulpSSH = new GulpSSH({
  ignoreErrors: false,
  sshConfig: config
})

gulp.task('exec', function () {
  return gulpSSH
    .exec(['uptime', 'ls -a', 'pwd'], {filePath: 'commands.log'})
    .pipe(gulp.dest('logs'))
})

gulp.task('dest', function () {
  return gulp
    .src(['./**/*.js', '!**/node_modules/**'])
    .pipe(gulpSSH.dest('/home/iojs/test/gulp-ssh/'))
})

gulp.task('sftp-read', function () {
  return gulpSSH.sftp('read', '/home/iojs/test/gulp-ssh/index.js', {filePath: 'index.js'})
    .pipe(gulp.dest('logs'))
})

gulp.task('sftp-write', function () {
  return gulp.src('index.js')
    .pipe(gulpSSH.sftp('write', '/home/iojs/test/gulp-ssh/test.js'))
})

gulp.task('shell', function () {
  return gulpSSH
    .shell(['cd /home/iojs/test/thunks', 'git pull', 'npm install', 'npm update', 'npm test'], {filePath: 'shell.log'})
    .pipe(gulp.dest('logs'))
})

API

var GulpSSH = require('gulp-ssh')

GulpSSH(options)

var gulpSSH = new GulpSSH(options)

options.sshConfig

Required Type: Object

  • host - String - Hostname or IP address of the server. Default: 'localhost'

  • port - Number - Port number of the server. Default: 22

  • username - String - Username for authentication. Default: (none)

  • password - String - Password for password-based user authentication. Default: (none)

  • privateKey - String or Buffer - Buffer or string that contains a private key for key-based user authentication (OpenSSH format). Default: (none)

More SSH Connection methods

options.ignoreErrors

Type: Boolean

Ignore errors when executing commands. Default: (false)


gulpSSH.connect(sshConfig)

return gulpSSH

gulpSSH.shell(commands, options)

return stream, there is a event "ssh2Data" on stream that emit ssh2 stream's chunk.

commands

Required Type: String or Array

options.filePath

Option Type: String

file path to write on local. Default: ('gulp-ssh.shell.log')

options.autoExit

Option Type: Boolean

auto exit shell. Default: (true)

gulpSSH.exec(commands, options)

return stream, there is a event "ssh2Data" on stream that emit ssh2 stream's chunk.

commands

Required Type: String or Array

options.filePath

Option Type: String

file path to write on local. Default: ('gulp-ssh.exec.log')

gulpSSH.sftp(command, filePath, options)

return stream

command

Required Type: String Value: 'read' or 'write'

filePath

Required Type: String

file path to read or write on server. Default: (none)

options

Option Type: Object

gulpSSH.dest(destDir, options)

return stream, copy the files to remote through sftp, acts similarly to Gulp dest, will make dirs if not exist.

gulpSSH.close()

Close the ssh connection.

License

MIT © Teambition

gulp-ssh's People

Contributors

davidvedvick avatar mervick avatar niksumeiko avatar purge avatar waganyushkin avatar zensh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.