jsftp-TypeError:createConnection不是一个函数 [英] jsftp - TypeError: createConnection is not a function

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

问题描述

我刚刚使用 client-ftp 发布了一个最近的问题,并被告知包已经过时,这是我最初的问题的根源.按照建议,我转到了一个仍在维护的软件包,它是 jsftp .但是,我仍然有类似的问题.作为参考,可以在此处找到我的上一个问题.我仍然会重申我的问题,因为它已经稍有改变.

I had just posted a recent question using client-ftp and was told that package was outdated and was the source of my original problem. As suggested I moved to an package that is still being maintained, which is jsftp. However, I am still having similiar issues. For reference my previous question can be found here. I will still restate my problem as it has changed slightly.

我是Angular/Node的新手,正在尝试连接到ftp服务器.

I am new to Angular/Node and am trying to connect to an ftp server.

我正在像这样在前端创建一个按钮:< button class ="btn btn-primary"(click)="downloadFile()">< i class ="fa fa-file-photo-o"></i>下载屏幕截图</button>

I am creating a button on the front end like this: <button class="btn btn-primary" (click)="downloadFile()"><i class="fa fa-file-photo-o"></i> Download Screenshot</button>

我要下载的新实现是这样的:

My new implementation to download is this:

downloadFile(){
    console.log('Connecting to sftp...');
    var jsftp = require("jsftp");

    var ftp = new jsftp({
        host: 'localhost',
        port: 22,
        user: 'anonymous',
        pass: 'anonymous'
    });

    console.log('Downloading Screenshot...');
}

我意识到我并没有在尝试下载任何内容,但是目前我只是在尝试先连接.问题是,触发click事件时,我收到一条错误消息,提示 TypeError:createConnection不是一个函数.我不知道我在做什么错. createConnection 函数未在任何地方调用.我正在按照文档中的说明进行操作,其他资源似乎也表明了这一点,例如此处.

I realize that I'm not trying to download anything, but for right now I'm only trying to connect first. The problem is that when the click event is fired I get an error saying TypeError: createConnection is not a function. I have no idea what I'm doing wrong. The createConnection function isn't being called anywhere. I'm doing what the documentaion says and other resources seem to indicate the same, such as here.

节点版本为:v8.11.3-也许这已经过时了?

Node version is: v8.11.3 - maybe that is too outdated?

推荐答案

您标记了打字稿,可能是因为 TypeError 引起的,这是JavaScript(而非打字稿)错误(请参见 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/参考/错误/Not_a_function ).

You tagged typescript, presumably because of the TypeError, which is a javascript, not a typescript, error (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function).

第二,您似乎对NodeJS(后端)和浏览器(前端)中的javascript感到困惑.您无法在浏览器中运行 jsftp ,因此您的方法需要更改.

Secondly, you seem to be confused between javascript on NodeJS, which is the back end, and in the browser, which is the front end. You cannot run jsftp in the browser, so your approach needs to change.

如果您要让用户单击链接时从浏览器下载ftp文件,则应该可以在href中直接链接该文件,而无需使用任何JavaScript.请查看此问题的答案以获取更多信息:是否可以使用Javascript从FTP下载文件?

If your intent is to let the user download an ftp file from their browser when they click the link, you should be able to link to it directly in the href, without any javascript. Take a look at the answers to this question for more info: Is it possible to download file from FTP using Javascript?

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

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