简体   繁体   English

jsftp-TypeError:createConnection不是函数

[英]jsftp - TypeError: createConnection is not a function

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. 我刚刚使用client-ftp发布了一个最近的问题,并被告知该软件包已过时,这是我原来的问题的根源。 As suggested I moved to an package that is still being maintained, which is jsftp . 根据建议,我移至一个仍在维护的软件包,即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. 我仍然会重申我的问题,因为它已经稍微改变了。

I am new to Angular/Node and am trying to connect to an ftp server. 我是Angular / Node的新手,正在尝试连接到ftp服务器。

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> 我在前端这样创建一个按钮: <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...');
}

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 . 问题是,在触发click事件时,我收到一条错误消息,提示TypeError: createConnection is not a function I have no idea what I'm doing wrong. 我不知道我在做什么错。 The createConnection function isn't being called anywhere. 未在任何地方调用createConnection函数。 I'm doing what the documentaion says and other resources seem to indicate the same, such as here . 我正在按照文档所说的去做,其他资源似乎也表明了这一点,例如here

Node version is: v8.11.3 - maybe that is too outdated? 节点版本为:v8.11.3-也许这已经过时了?

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 ). 您标记了打字稿,大概是因为TypeError ,这是JavaScript(而非打字稿)错误(请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function )。

Secondly, you seem to be confused between javascript on NodeJS, which is the back end, and in the browser, which is the front end. 其次,您似乎对NodeJS(后端)和浏览器(前端)中的javascript感到困惑。 You cannot run jsftp in the browser, so your approach needs to change. 您无法在浏览器中运行jsftp ,因此您的方法需要更改。

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. 如果您要让用户单击链接时从浏览器下载ftp文件,则应该可以直接在href中链接该文件,而无需使用任何JavaScript。 Take a look at the answers to this question for more info: Is it possible to download file from FTP using Javascript? 请查看该问题的答案以获取更多信息: 是否可以使用Javascript从FTP下载文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM