Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for SFTP #136

Closed
john30 opened this issue Jul 13, 2018 · 5 comments
Closed

support for SFTP #136

john30 opened this issue Jul 13, 2018 · 5 comments

Comments

@john30
Copy link

john30 commented Jul 13, 2018

when using node 10, it seems support for sftp protocol is there on Windows but not on Linux

@JCMais
Copy link
Owner

JCMais commented Aug 13, 2018

can you try again that? If the error persists, can you share a code that reproduces this?

Thanks

@john30
Copy link
Author

john30 commented Sep 27, 2018

here is some code to reproduce:

var libcurl = require("node-libcurl");
var url = 'sftp://test.rebex.net/';
var username = 'demo';
var password = 'password';
var handle = new libcurl.Easy();
handle.setOpt(libcurl.Curl.option.USERNAME, username);
handle.setOpt(libcurl.Curl.option.PASSWORD, password);
handle.setOpt(libcurl.Curl.option.FAILONERROR, true);
handle.setOpt(libcurl.Curl.option.URL, url);
var found = 0;
handle.setOpt(libcurl.Curl.option.WRITEFUNCTION, function (buff, size, nmemb) {
    found++;
    return size * nmemb;
});
var code = handle.perform();
handle.close();
if (code !== libcurl.Curl.code.CURLE_OK) {
    var err = libcurl.Easy.strError(code);
    console.log('error: ', code, err);
} else {
    console.log('OK', found);
}

this gives the following results:

  • Linux, node v9.3.0:
    error: 1 Unsupported protocol
  • Linux, node v10.4.1:
    error: 1 Unsupported protocol
  • Linux, node v10.11.0:
    error: 1 Unsupported protocol
  • Windows, node v8.11.3:
    OK 5
  • Windows, node v10.11.0:
    Segmentation fault

@JCMais
Copy link
Owner

JCMais commented Sep 27, 2018

Thanks for the code, I will do some digging later this week .

@imade
Copy link

imade commented Jan 2, 2019

I had same issue with macOS High Sierra (10.13.6) and node v10.15.0 but with the steps below I got it working.

Tested node-libcurl SFTP based on the official example code

Output:

sftp-test $ node index.js 
* Rebuilt URL to: sftp://<hidden>:<hidden>@<hidden>/
* Protocol "sftp" not supported or disabled in libcurl
* Closing connection -1
1 false 'Unsupported protocol'

Next verified that my local curl itself actually supports SFTP:

$ curl -k "sftp://<hidden>:22/myuser/somefolder/" --user "<hidden>:<hidden>"

This gave similar error: Protocol sftp not supported or disabled in libcurl

Based on this blog post I found out how to enable sftp with curl. I didn't follow the steps exactly as I got it working using brew.

First verified that my machine has libssh2 available when I want to install curl.

$ brew info curl

This should show green check mark next to libssh2.

Next installed curl itself:

$ brew install --with-libssh2 curl
$ echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ curl -k "sftp://<hidden>:22/myuser/somefolder/" --user "<hidden>:<hidden>"

As final step I re-installed my node-libcurl dependency an ensured it would link to new system libcurl.

$ export LDFLAGS="-L/usr/local/opt/curl/lib"
$ export CPPFLAGS="-I/usr/local/opt/curl/include"
$ npm i

Also worth noting is that my package.json has a preinstall step for node-libcurl:

"scripts": {
  "preinstall": "npm install --build-from-source node-libcurl"
}

After all these steps the original test code started working properly.

Given macOS and Linux are very similar it might help with the Linux issues too.

@JCMais
Copy link
Owner

JCMais commented Apr 20, 2019

This has been fixed on develop branch.

@JCMais JCMais closed this as completed Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants