SSH and SFTP tasks for gulp
Install with npm
npm install --save-dev gulp-ssh
var gulp = require('gulp');
var gulpSSH = require('gulp-ssh')({
ignoreErrors: false,
sshConfig: {
host: 'angularjs.cn',
port: 22,
username: 'root',
privateKey: require('fs').readFileSync('/Users/zensh/.ssh/id_rsa')
}
});
// execute commands
gulp.task('exec', function () {
return gulpSSH
.exec(['uptime', 'ls -a', 'pwd'], {filePath: 'commands.log'})
.pipe(gulp.dest('logs'));
});
// get file from server and write to local
gulp.task('sftp-read', function () {
return gulpSSH.sftp('read', 'pm2.json')
.pipe(gulp.dest(''));
});
// put local file to server
gulp.task('sftp-write', function () {
return gulp.src('index.js')
.pipe(gulpSSH.sftp('write', 'test.js'));
});
// execute commands in shell
gulp.task('shell', function () {
return gulpSSH
.shell(['cd /home/thunks', 'git pull', 'npm install', 'npm update', 'npm test'], {filePath: 'shell.log'})
.pipe(gulp.dest('logs'));
});
var GulpSSH = require('gulp-ssh');
var gulpSSH = new GulpSSH(options);
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
orBuffer
- Buffer or string that contains a private key for key-based user authentication (OpenSSH format). Default: (none)
Type: Boolean
Ignore errors when executing commands. Default: (false)
return gulpSSH
return stream
Required
Type: String
or Array
Option
Type: String
file path to write on local. Default: ('gulp-ssh.shell.log')
Option
Type: Boolean
auto exit shell. Default: (true)
return stream
Required
Type: String
or Array
Option
Type: String
file path to write on local. Default: ('gulp-ssh.exec.log')
return stream
Required
Type: String
Value: 'read' or 'write'
Required
Type: String
file path to read or write on server. Default: (none)
Option
Type: Object
MIT © Teambition