當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ftp.connect函數代碼示例

本文整理匯總了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 }
    });
  }
開發者ID:joedono,項目名稱:No-CI,代碼行數:26,代碼來源:ftp-upload.service.ts

示例2:

 }).on('error', (err) => {
   if (options.attempts > limit) {
     deferred.reject(err);
   }
   options.attempts++;
   ftp.connect(options);
 });
開發者ID:chrisk-symphony,項目名稱:sy-trans,代碼行數:7,代碼來源:FTP.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: 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

示例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 }
    });
  }
開發者ID:joedono,項目名稱:No-CI,代碼行數:42,代碼來源:ftp-upload.service.ts

示例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;
  }
開發者ID:chrisk-symphony,項目名稱:sy-trans,代碼行數:24,代碼來源:FTP.ts

示例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 });
開發者ID:ColinDabritz,項目名稱:vsts-tasks,代碼行數:30,代碼來源:ftpuploadtask.ts


注:本文中的ftp.connect函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。