Thursday 31 March 2016

Deploy files to ftp using gulp

Introduction:

Here i am going to explain how to move your files to ftp using gulp.

Step 1 :

   Install necessary gulp required files.

Install gulp-util and gulp-ftp

  1. var gutil = require('gulp-util');
  2. var ftp = require('gulp-ftp');


Step 2: How to install gulp packages:

Go to your command prompt and your Gulp directory

F:\gulpdir\npm install --save gulp-util

F:\gulpdir\npm install --save gulp-ftp


And then add this code to your gulfile.js
  1. gulp.task('deploy', function () {

  2.     var conn = ftp.create({
  3.         host: '192.168.3.5',  // your ftp address
  4.         user: 'username',  //Ftp user name
  5.         password: 'Password', //Ftp Password
  6.         parallel: 10,
  7.         log: gutil.log
  8.     });

  9.     var globs = [
  10.         'src/**',    //Your source files
  11.         'index.html'
  12.     ];

  13.     // using base = '.' will transfer everything to /public_html correctly 
  14.     // turn off buffering in gulp.src for best performance 

  15.     return gulp.src(globs, { base: '.', buffer: false })
  16. .pipe(conn.newer('/public_html')) // only upload newer files 
  17. .pipe(conn.dest('/public_html'));   //Destination folder

  18. });
  19. gulp.task('default', function (done) {
  20.     runSequence( 'deploy', done);
  21. });

No comments:

Post a Comment