Skip to content

Commit

Permalink
fix: use new URL() for server/port, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jul 4, 2017
1 parent f52fb2f commit ac0f302
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/sftp-scheme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { URLScheme } from 'url-resolver-fs';
const Client = require('ssh2-sftp-client');
const { URL } = require('url');

function invalidURLError(url) {
Promise.reject(new Error(`Invalid sftp url: ${url}`));
Expand Down Expand Up @@ -42,15 +43,17 @@ export default class SFTPScheme extends URLScheme {
const m = url.match(/^sftp:\/\/(.*)/);

if (m) {
url = new URL(url);
const sftp = new Client();

const conn = await sftp.connect({
host: '127.0.0.1',
port: '8080',
username: 'username',
host: url.host,
port: url.port || this.constructor.defaultPort,
username: url.username,
password: '******'
});

return conn.get(url.path);
return conn.get(url.pathname);
}

return invalidURLError(url);
Expand Down

0 comments on commit ac0f302

Please sign in to comment.