TypeError: Socket is not a constructor
TypeError: Socket is not a constructor
我是 Angular/Node 的新手,似乎无法解决我遇到的问题。
我正在尝试使用 client-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 并在构造函数中创建一个私有客户端参数并处理它,但这似乎也不起作用。
我知道构造函数是由 new 关键字隐式调用的,但我没有在我的代码中的任何地方引用 'Socket'。也许我遗漏了什么?
这是我的导入和构造函数供参考:
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, ' ', ' ', ' ', ' ', ' ');
}
初步概览
client.download
方法中的文件路径存在异常。路径 /stfFilepPath
似乎多了一个 'p'。尝试删除它,除非那是路径的实际名称。
所以;
client.download('/sftFilepPath', './Downloads'
变成
client.download('/sftFilePath', './Downloads'
尝试一下,如果有效请告诉我。如果不行,试试 Lynx 的解决方案。
我猜你的 ftp 客户端太旧了。系统环境变化越来越快。但是这个客户端自 2015 年以来就没有更新过。尝试使用像 jsftp
这样的最新客户端
我是 Angular/Node 的新手,似乎无法解决我遇到的问题。
我正在尝试使用 client-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 并在构造函数中创建一个私有客户端参数并处理它,但这似乎也不起作用。
我知道构造函数是由 new 关键字隐式调用的,但我没有在我的代码中的任何地方引用 'Socket'。也许我遗漏了什么?
这是我的导入和构造函数供参考:
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, ' ', ' ', ' ', ' ', ' ');
}
初步概览
client.download
方法中的文件路径存在异常。路径 /stfFilepPath
似乎多了一个 'p'。尝试删除它,除非那是路径的实际名称。
所以;
client.download('/sftFilepPath', './Downloads'
变成
client.download('/sftFilePath', './Downloads'
尝试一下,如果有效请告诉我。如果不行,试试 Lynx 的解决方案。
我猜你的 ftp 客户端太旧了。系统环境变化越来越快。但是这个客户端自 2015 年以来就没有更新过。尝试使用像 jsftp
这样的最新客户端