我刚接触过角/节点,似乎找不出我遇到的问题。
我正试图使用客户端ftp连接到ftp,并且在实现上遇到了问题。实际上,我在前端创建了一个按钮,如下所示:
<button class="btn btn-primary" (click)="downloadFile()"><i class="fa fa-file-photo-o"></i> Download Screenshot</button>
并通过这样的单击事件来实现它:
downloadFile(){
console.log('Connecting to sftp...');
var ftpClient = require('ftp-client'),
config = {
host: 'localhost',
port: 22,
user: 'anonymous',
password: 'anonymous'
},
options = {
logging: 'basic'
},
client = new ftpClient(config, options);
console.log('Downloading Screenshot...');
client.connect(function () {
client.download('/sftFilepPath', './Downloads', {
overwrite: 'none'
}, function (result) {
console.log(result);
});
});
}我一直收到一个错误,但是我说:只要按下按钮,就会出现TypeError: Socket is not a constructor。我将在调试器中显示两个console.log()调用,因此我假设这与我试图连接和下载的位置有关。
我试着为FtpClient命名空间调用import,并在构造函数中创建一个私有客户端参数,并对其进行处理,但这似乎也不起作用。
我知道构造函数是由新关键字隐式调用的,但我的代码中没有引用“套接字”。也许我漏掉了什么?
下面是我的导入和构造函数,以供参考:
import { Component, ElementRef, Input, OnInit, OnDestroy } from '@angular/core';
import { TestInstance, Test, TestDetails } from '../../objModules/index';
import { RunServices } from './run.services';
import { Observable } from 'rxjs/Rx';
import * as $ from 'jquery';
import * as _ from 'underscore';
import { ModalController } from './run.modal.controller';
// import { FtpClient } from 'ftp-client';
@Component({
templateUrl: './run.modal.component.html',
moduleId: module.id.toString(),
selector: 'app-test-data',
providers: [ RunServices ]
})
export class ModalComponent implements OnInit, OnDestroy {
testInstance: TestDetails;
id: string;
private element: JQuery;
private runId: string;
private test$: Observable<Test>;
private testHistory$: Observable<TestInstance[]>;
private test: Test;
private testHistory: TestInstance[];
private selectedTest: TestInstance;
private latestRuns: TestInstance[];
private averagePass: number;
private averageFail: number;
services: RunServices;
constructor(private modalController: ModalController, private el: ElementRef, private runServices: RunServices) {
this.element = $(el.nativeElement);
this.services = runServices;
// Initialize these objects so we don't get any errors
this.test = new Test(' ', ' ', ' ', [' '], ' ', ' ');
this.testHistory = new Array<TestInstance>(new TestInstance(' ', ' ', ' ', 0, ' ', ' ', ' ', ' ', ' '));
this.testInstance = new TestDetails(' ', ' ', ' ', ' ', ' ', ' ', ' ', 0, null, ' ');
this.selectedTest = new TestInstance(' ', ' ', ' ', 0, ' ', ' ', ' ', ' ', ' ');
}发布于 2018-08-02 04:44:07
我猜你的ftp客户端太老了。系统环境的变化越来越快。但这个客户自2015年以来就没有更新过。尝试使用像jsftp这样的最新客户端。
发布于 2018-08-02 04:37:02
初始概述
client.download方法中有一个异常是您的文件路径。路径/stfFilepPath似乎有一个额外的'p‘。尝试删除它,除非这是路径的实际名称。
是这样的;
client.download('/sftFilepPath', './Downloads'
变成了
client.download('/sftFilePath', './Downloads'
试一试,让我知道它是否有效。如果不试试Lynx的解决方案。
https://stackoverflow.com/questions/51641736
复制相似问题