我正在尝试编写一个 gulp 脚本,该脚本将监视我更改的文件(前端文件,如 css、js、cshtml),并在它们被修改时将它们 FTP 到我的 Azure WebApp。我正在使用 gulp-ftp,但如果有更好的选择,请告诉我。
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;
})
);
});
我已经使用 FileZilla 检查了 FTP 的凭据,它工作正常。(我使用这里的方法提取它们)。
手表似乎工作正常,但 FTP 似乎失败并出现以下错误:
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)
有谁知道为什么连接不上?
我也不确定我的脚本是否会将文件复制到网站的相对位置,或者它是否会直接进入根目录.....但这完全是另一个问题。