2

I'm attempting to put together a gulp script that will watch my changed files (front end files like css, js, cshtml) and will FTP them to my Azure WebApp the moment they are modified. I'm using gulp-ftp, but if there is a better option, please let me know.

  gulp.src(cssRoot).pipe(
    foreach(function (stream, rootFolder) {
      gulp.watch([cssRoot + "/**/*.css", jsRoot + "/**/*.js", cshtmlRoot + "/**/*.cshtml"], function (event) {
        if (event.type === "changed") {
          console.log("publish file " + event.path);
          gulp.src(event.path, { base: './' })
          .pipe(ftp({
            host: 'ftp://my-azure.website-ftp-url/',
            user: 'my-azure-ftp-username\in-the-complete-form',
            pass: 'my-azure-ftp-password',
            remotePath: 'site\wwwroot\'
          }))
          .pipe(gutil.noop());
        }
        console.log("published " + event.path);
      });
      return stream;
    })
  );
});

I have checked the credentials for the FTP using FileZilla and it works fine. (I extracted them using the method here).

The watch seems to be working fine, however the FTP seems to be failing with the following error:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: getaddrinfo ENOTFOUND ftp://my-azure.website-ftp-url/ ftp://my-azure.website-ftp-url/:21
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

Does anyone know why it can't connect?

I'm also not sure if my script will copy the file to the relative location of the website, or if it'll go directly to the root.....but that's another question altogether.

Sean Holmesby
  • 2,135
  • 3
  • 23
  • 34

2 Answers2

2

Well, gulp-ftp does say it is deprecated in favor of vinyl-ftp although that isn't probably your problem. I would remove the "ftp://" from your host value (if it is there) and see it if works better.

Here is a very nice blog on using vinyl-ftp using gulp with vinyl-ftp. vinyl-ftp also can handle transferring only newer files nicely too.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • Fantastic, thank you. Both this and Aaron's answers helped me out. Up vote for being first and pointing to vinyl-ftp, but I had to give the 'correct' answer to Aaron as well for the user value fix which was also a problem in my code. Thanks to both of you! – Sean Holmesby May 02 '17 at 16:45
1
  • As @Mark pointed out, please remove "ftp://" from your host value first.

  • Then you'll also need to double the "\" in the user value (ex: "someapp\\someuser"). See Vinyl-ftp strange error.

Community
  • 1
  • 1
Aaron Chen
  • 9,835
  • 1
  • 16
  • 28