本文整理汇总了TypeScript中ftp.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testConnection
public testConnection(host: string, port: number, username: string, password: string): void {
var client = new ftp();
client.on('ready', () => {
client.list((err, list) => {
if (err) console.error(err);
console.dir(list);
client.end();
alert("Connection Successful");
});
});
client.on('error', (err) => {
console.error(err);
});
client.connect({
host: host,
port: port,
user: username,
password: password,
secure: true,
secureOptions: { rejectUnauthorized: false }
});
}
示例2:
}).on('error', (err) => {
if (options.attempts > limit) {
deferred.reject(err);
}
options.attempts++;
ftp.connect(options);
});
示例3: _createReadableStream
/**
* @hidden and @ignore
*/
public _createReadableStream(option: FtpReadOption): Readable {
const connector = new Connector();
if (option.path === undefined) {
const reader = new Readable();
process.nextTick(() => {
reader.emit("error", new Error(SourceError[421]), option);
reader.destroy();
});
return reader;
} else {
const client = new Client();
client.on("ready", () => {
client.get(option.path as string, (e, stream) => {
if (e) {
connector.emit("error", e, option);
connector.destroy();
} else {
stream.pipe(connector);
stream.on("close", () => {
client.end();
// self.emit('end', self);
});
}
});
});
// connect to localhost:21 as anonymous
// client.on("error", (error) => {
// err = error;
// });
client.connect(option);
}
return connector as Readable;
}
示例4: writeFile
writeFile (options: any, file: any) {
options.user = options.username ? options.username : options.user;
const ftp = new nodeFTP(),
deferred = this.deferred(),
limit = 20;
options.attempts = 0;
ftp.on('ready', () => {
const writeStream = new Writable(file.path);
const readStream = new Readable();
readStream.push(file.content);
readStream.push(null);
ftp.put(readStream, file.path, (err) => {
if (err) {
deferred.reject(err);
}
ftp.end();
deferred.resolve({});
});
}).on('error', (err) => {
if (options.attempts > limit) {
deferred.reject(err);
}
options.attempts++;
ftp.connect(options);
});
ftp.connect(options);
return deferred.promise;
}
示例5: readFile
readFile(options: any, file: any) {
options.user = options.username ? options.username : options.user;
const deferred = this.deferred();
const ftp = new nodeFTP();
ftp.on('ready', () => {
ftp.get(file.path, (err, stream) => {
if (err) {
deferred.reject(err);
}
let content = "";
stream.on('data', (chunk) => {
content += chunk;
}).on('end', () => {
ftp.end();
deferred.resolve(content);
}).on('error', (err) => {
ftp.end();
deferred.reject(err);
});
})
});
ftp.connect(options);
return deferred.promise;
}
示例6: moveFile
moveFile (options: any, fromPath: string, toPath: string) {
options.user = options.username ? options.username : options.user;
const ftp = new nodeFTP(),
deferred = this.deferred(),
limit = 20;
options.attempts = 0;
ftp.on('ready', () => {
ftp.rename(fromPath, toPath, (err, data) => {
if (err) {
deferred.reject(err);
}
ftp.end();
deferred.resolve({});
});
}).on('error', (err) => {
if (options.attempts > limit) {
deferred.reject(err);
}
options.attempts++;
ftp.connect(options);
});
ftp.connect(options);
return deferred.promise;
}
示例7: Promise
return new Promise((resolve) => {
const ftp = new FtpClient();
ftp.on("error", (err) => {
ftp.end();
console.log(err);
resolve(localStat);
});
ftp.on("ready", () => {
ftp.list(jdfPath, (err, list) => {
if (err) {
ftp.end();
console.log(err);
resolve(localStat);
} else {
const index = indexOfJdf(list);
if (index >= 0) {
const remoteStat = list[indexOfJdf(list)];
if (localStat
&& (localStat.size === parseInt(remoteStat.size)
&& localStat.mtime.getTime() == remoteStat.date.getTime())) {
ftp.end();
resolve(localStat);
} else {
ftp.get(remoteJdfPath, (err, stream) => {
if (err) {
ftp.end();
console.log(err);
resolve(localStat);
} else {
stream.once("close", () => {
ftp.end();
});
stream.pipe(fs.createWriteStream(localJdfPath).once("close", () => {
fs.utimesSync(localJdfPath, new Date, remoteStat.date);
resolve(getFileStat(localJdfPath));
}));
}
});
}
} else {
ftp.end();
resolve(localStat);
}
}
});
});
ftp.connect({
// secure: true,
// secureOptions: {
// rejectUnauthorized: false
// },
// user: "",
// password: "",
host: cisjr
});
});
示例8: upload
public upload(rootPath: string, files: CommitFile[], ftpConfig: FtpConfig, logger: EventEmitter<string>) {
rootPath = rootPath.replace(/\\/gi, "/") + "/";
var ftpRootFolder = ftpConfig.IsStaging ? StagingFolder : ProductionFolder;
var client = new ftp();
logger.emit('Repo Selected: ' + rootPath);
logger.emit('Files Queued: ' + files.length);
client.on('ready', () => {
logger.emit('Connected to FTP Server');
files.forEach((commitFile) => {
if(commitFile.Status === 'A' || commitFile.Status === 'M') {
logger.emit('Uploading: ' + rootPath + commitFile.FileName);
logger.emit('To: ' + ftpRootFolder + commitFile.FileName);
client.put(rootPath + commitFile.FileName, ftpRootFolder + commitFile.FileName, (err) => {
if(err) {
logger.emit('ERROR: ' + err);
} else {
logger.emit('Upload successful: ' + commitFile.FileName);
}
});
}
});
client.end();
});
client.on('error', (err) => {
logger.emit('ERROR: ' + err);
});
client.connect({
host: ftpConfig.Host,
port: ftpConfig.Port,
user: ftpConfig.Username,
password: ftpConfig.Password,
secure: true,
secureOptions: { rejectUnauthorized: false }
});
}
示例9: readDir
readDir(options: any, path: string) {
options.user = options.username ? options.username : options.user;
const deferred = this.deferred();
const me = this,
ftp = new nodeFTP();
ftp.on('ready', () => {
ftp.list(path, (err, list) => {
if (err) {
// throw err;
deferred.reject(err);
}
deferred.resolve(list);
});
});
ftp.on('error', (err) => {
deferred.reject(err);
});
ftp.connect(options);
return deferred.promise;
}
示例10: function
}
c.on('ready', function () {
tl.debug('connected to ftp host:' + serverEndpointUrl.host);
if (clean) {
tl.debug('cleaning remote: ' + remotePath);
remoteExists(remotePath, function(exists){
if(exists){
c.rmdir(remotePath, true, function (err) {
if (err) {
c.destroy();
failTask('Unable to clean remote folder: ' + remotePath + ' error: ' + err);
}
uploadFiles();
});
} else {
uploadFiles();
}
});
} else {
tl.debug('skipping clean: ' + remotePath);
uploadFiles();
}
});
var secure = serverEndpointUrl.protocol.toLowerCase() == 'ftps:' ? true : false;
tl.debug('secure ftp=' + secure);
c.connect({ 'host': serverEndpointUrl.host, 'user': username, 'password': password, 'secure': secure });