question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is possibile to use proxy with sftp connection ?

See original GitHub issue

let Client = require('ssh2-sftp-client'); let sftp = new Client(); sftp.connect({ host: '127.0.0.1', port: '8080', username: 'username', password: '******' }).then(() => { return sftp.list('/pathname'); }).then((data) => { console.log(data, 'the data info'); }).catch((err) => { console.log(err, 'catch error'); });

I use this type of code but is there an option for setting proxy ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jmorinocommented, Jun 14, 2019

I struggled a bit for having this module work behind a corporate proxy, trying with ssh2, socksv5 and some of its forks.

I finally got it working using the (very simple to use) socks module.

Here is my solution:

import { SocksClient } from 'socks';
import SFTPClient from 'ssh2-sftp-client';

const host = 'my-sftp-server.net';
const port = 22; // default SSH/SFTP port on remote server

// connect to SOCKS 5 proxy
const { socket } = await SocksClient.createConnection({
  proxy: {
    host: 'my.proxy', // proxy hostname
    port: 1080, // proxy port
    type: 5, // for SOCKS v5
  },
  command: 'connect',
  destination: { host, port } // the remote SFTP server
});

const client = new SFTPClient();
await client.connect({
  host,
  sock: socket, // pass the socket to proxy here (see ssh2 doc)
  username: '.....',
  privateKey: '.....'
});

// client is connected
1reaction
amstradcommented, Jun 17, 2019

My bad, got this working using @jmorino solution, just dunno why but i need to pass the socket property in the object… my code is as follow:

const {socket} = await SocksClient.createConnection(options)
                console.log('SCOCKET CONNECTED. Connecting to SFTP...')
                const sftp_client = new SFTPClient();
                await sftp_client.connect({
                    host: '****',
                    sock: socket.socket,
                    port: 22, // Normal is 22 port
                    username: '***',
                    password: '***',
                    algorithms: {
                        serverHostKey: ['ssh-rsa', 'ssh-dss'],
                    },
                }).then(async () => {

                    console.log('SFTP CONNECTED!')
    

                }).catch((err) => {
                    console.log('error ' + err)
 
                });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: sftp routing through proxy server - HPE Community
When a proxy is involved, your sftp client opens a TCP connection to the proxy using a specific proxy protocol (HTTP CONNECT, in...
Read more >
Proxy Details with SFTP command - Stack Overflow
I use the following command (Cygwin) for connecting to SFTP servers over SOCKS proxy: sftp -oProxyCommand ...
Read more >
Connecting with sftp using a proxy server - Unix Stack Exchange
I can connect using WinSCP so the connection details are correct. Any assistance is greatly appreciated! bash · proxy · sftp · netcat...
Read more >
How To Set Up An SFTP Reverse Proxy in JSCAPE MFT ...
An SFTP reverse proxy adds another layer of security to SFTP services. In addition to SFTP's ability to encrypt data in transit and...
Read more >
Using SFTP with .NET via a proxy - QuotaGuard
You can use the Renci SFTP library to route SFTP transfers via QuotaGuard Static from your .NET app, allowing you to lock down...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found