The vinyl-ftp package has a function clean() but I'm not sure how to use it right. I need to:
build folderI have the following gulp task:
gulp.task('deploy', () => {
  let conn = ftp.create({host:host,user:user,password: password});
  return gulp.src('build/**', {base: './build/', buffer: false })
      .pipe(conn.newer('/path/on/my/server/')) // only upload newer files
      .pipe(conn.dest('/path/on/my/server/'))
      .pipe(conn.clean('build/**', './build/'));
});
1) and 2) is OK, but the clean() function does nothing
The vinyl-ftp docs have this to say:
conn.clean( globs, local[, options] )
Globs remote files, tests if they are locally available at
<local>/<remote.relative>and removes them if not.
Note that globs expects a path for the remote files on your FTP server. Since your remote files are located in /path/on/my/server/ you have to specify that path as your glob:
  .pipe(conn.clean('/path/on/my/server/**', './build/'));
Since I got a lot of struggle with this, here a working peace of code. It removes all files from the server that dont exist locally except the usage folder:
var connection = ftp.create({ ... });
connection.clean([
    '/*.*',
    '/!(usage)*',
    '/de/**',
    '/en/**',
    '/images/**',
    '/fonts/**',
    '/json/**',
    '/sounds/**'
], './dist', { base: '/' });
My files are locally on the ./dist folder and remote directly in the root directory (/) (of the used ftp user).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With