当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ftp.on函数代码示例

本文整理汇总了TypeScript中ftp.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了on函数的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 }
    });
  }
开发者ID:joedono,项目名称:No-CI,代码行数:26,代码来源:ftp-upload.service.ts

示例2: 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
        });
    });
开发者ID:graycrow,项目名称:node-cisjr,代码行数:59,代码来源:index.ts

示例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;
 }
开发者ID:node-dmr,项目名称:dmr-source,代码行数:36,代码来源:source-ftp.ts

示例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;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:32,代码来源:FTP.ts

示例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;

  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:28,代码来源:FTP.ts

示例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;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:28,代码来源:FTP.ts

示例7: 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 }
    });
  }
开发者ID:joedono,项目名称:No-CI,代码行数:42,代码来源:ftp-upload.service.ts

示例8: 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;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:24,代码来源:FTP.ts

示例9: 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);
开发者ID:ColinDabritz,项目名称:vsts-tasks,代码行数:30,代码来源:ftpuploadtask.ts

示例10: doWork

function doWork() {
    tl.setResourcePath(path.join( __dirname, 'task.json'));

    let ftpOptions: FtpOptions = getFtpOptions();
    if (!ftpOptions.serverEndpointUrl.protocol) {
        tl.setResult(tl.TaskResult.Failed, tl.loc('FTPNoProtocolSpecified'));
    }
    if (!ftpOptions.serverEndpointUrl.hostname) {
        tl.setResult(tl.TaskResult.Failed, tl.loc('FTPNoHostSpecified'));
    }

    let ftpClient: any = new Client();
    let ftpHelper: ftputils.FtpHelper = new ftputils.FtpHelper(ftpOptions, ftpClient);

    let files: string[] = ftputils.findFiles(ftpOptions);
    tl.debug('number of files to upload: ' + files.length);
    tl.debug('files to upload: ' + JSON.stringify(files));

    let uploadSuccessful: boolean = false;

    ftpClient.on('greeting', (message: string) => {
        tl.debug('ftp client greeting');
        console.log(tl.loc('FTPConnected', message));
    });

    ftpClient.on('ready', async () => {
        tl.debug('ftp client ready');
        try {
            if (ftpOptions.clean) {
                console.log(tl.loc('CleanRemoteDir', ftpOptions.remotePath));
                await ftpHelper.cleanRemote(ftpOptions.remotePath);
            } else if (ftpOptions.cleanContents) {
                console.log(tl.loc('CleanRemoteDirContents', ftpOptions.remotePath));
                await ftpHelper.cleanRemoteContents(ftpOptions.remotePath);
            }

            console.log(tl.loc('UploadRemoteDir', ftpOptions.remotePath));
            await ftpHelper.uploadFiles(files);
            uploadSuccessful = true;
            console.log(tl.loc('UploadSucceedMsg', ftpHelper.progressTracking.getSuccessStatusMessage()));

            tl.setResult(tl.TaskResult.Succeeded, tl.loc('UploadSucceedRes'));
        } catch (err) {
            failTask(err);
        } finally {
            console.log(tl.loc('DisconnectHost', ftpOptions.serverEndpointUrl.host));
            ftpClient.end();
            ftpClient.destroy();
        }
    });

    ftpClient.on('close', (hadErr: boolean) => {
        console.log(tl.loc('Disconnected'));
        tl.debug('ftp client close, hadErr:' + hadErr);
    });

    ftpClient.on('end', () => {
        tl.debug('ftp client end');
    })

    ftpClient.on('error', (err) => {
        tl.debug('ftp client error, err: ' + err);
        if (!uploadSuccessful) {
            // once all files are successfully uploaded, a subsequent error should not fail the task
            failTask(err);
        }
    })

    let verboseSnippet: string[] = [];
    let debugLogger:any = function(message) {
        verboseSnippet.push(message);
        if (verboseSnippet.length >= 5) {
            verboseSnippet.shift();
        }
        tl.debug(message);
    };
    function failTask(message: string): void {
        let fullMessage: string = `FTP upload failed: "${message}". FTP log: "${verboseSnippet}".`;
        if (ftpHelper.progressTracking) {
            fullMessage += ftpHelper.progressTracking.getFailureStatusMessage();
        }
        console.log(fullMessage);
        tl.setResult(tl.TaskResult.Failed, message);
    }

    let secure: boolean = ftpOptions.serverEndpointUrl.protocol.toLowerCase() == 'ftps:' ? true : false;
    tl.debug('secure ftp=' + secure);

    let secureOptions: any = { 'rejectUnauthorized': !ftpOptions.trustSSL };

    let hostName: string = ftpOptions.serverEndpointUrl.hostname;
    let port: string = ftpOptions.serverEndpointUrl.port;
    if (!port) { // port not explicitly specifed, use default
        port = '21';
        tl.debug('port not specifided, using default: ' + port);
    }

    console.log(tl.loc('ConnectPort', hostName, port));
    ftpClient.connect({ 'host': hostName, 'port': port, 'user': ftpOptions.username, 'password': ftpOptions.password, 'secure': secure, 'secureOptions': secureOptions, 'debug': debugLogger });
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:100,代码来源:ftpuploadtask.ts


注:本文中的ftp.on函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。