TypeError:套接字不是构造函数 [英] TypeError: Socket is not a constructor

查看:89
本文介绍了TypeError:套接字不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular / Node的新手,似乎无法找出我遇到的问题。

I'm new to Angular/Node and cannot seem to figure out a problem I'm having.

我正在尝试使用<连接到ftp a href = https://github.com/noodny/node-ftp-client rel = nofollow noreferrer> client-ftp ,并且在实现方面遇到麻烦。本质上,我是在前端创建这样的按钮:

I'm trying to connect to an ftp using client-ftp and am having trouble with the implementation. Essentially I'm creating a button on the front end like this:

< button class = btn btn-primary(click)= downloadFile()>< i class = fa fa-file-photo-o>< / i>下载屏幕快照< / button>

并尝试通过以下单击事件来实现它:

And implementing trying to implement it via a click event like this:

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 :每当按下按钮时,套接字就不是构造函数。我同时收到两个console.log()调用,以在调试器中显示,因此我认为这与我尝试实际连接和下载的位置有关。

I keep getting an error, however saying: TypeError: Socket is not a constructor whenever the button is pressed. I'm getting both of my console.log() calls to show in the debugger so I assume it has to do with where I'm trying to actually connect and download.

我尝试为FtpClient命名空间调用import并在构造函数中创建一个私有客户端参数并加以解决,但这似乎也不起作用。

I tried calling import for the FtpClient namespace and making a private client parameter in the constructor and working off of that, but that doesn't seem to work either.

我知道new关键字会隐式调用一个构造函数,但是我在代码的任何地方都没有引用 Socket。也许我丢失了什么?

I know a constructor is implicitly called by the new keyword, but I don't reference 'Socket' anywhere in my code. Maybe I'm missing something?

这是我的导入文件和构造函数供参考:

Here is my imports and constructor for reference:

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, ' ', ' ', ' ', ' ', ' ');
    }


推荐答案

我的猜测是您的ftp客户年龄太大。系统环境变化越来越快。但是,此客户端自2015年以来就没有进行过更新。尝试使用最新的客户端,例如 jsftp

My guess is that your ftp client is too old. System environments change more and more rapidly. But this client hasn't been updated since 2015. Try to use an up-to-date client like jsftp

这篇关于TypeError:套接字不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆