Socket
Socket
Sign inDemoInstall

@passioncloud/sftp-connection

Package Overview
Dependencies
31
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

34

index.js
const Client = require('ssh2-sftp-client');
const sftp = new Client();
let currentHost = ''
let currentPort = ''

@@ -12,4 +14,11 @@ async function establishSftpConnection({

}) {
const sftpConnectionAvailable = await isSftpConnectionAvailable();
const sftpConnectionAvailable = await isSftpConnectionAvailable({
host,
port,
});
// for this connection to work, on windows, SYSTEM must have permissions to read the private key
if (!sftpConnectionAvailable) {
currentHost = host
currentPort = port
await sftp.connect({

@@ -20,3 +29,3 @@ host,

password,
privateKey
privateKey,
});

@@ -26,6 +35,21 @@ }

async function isSftpConnectionAvailable() {
async function isSftpConnectionAvailable({
host,
port
}) {
try {
await sftp.exists('/');
return true;
if (host == currentHost && port === currentPort) {
// you are connection to the same sftp server and a connection
// already exists. return true
return true;
}
else {
// you are trying to connect to a different sftp server
// end the current sftp connection and then return false
currentHost = host
currentPort = port
await sftp.end()
return false;
}
}

@@ -47,3 +71,3 @@ catch (e) { return false; }

password,
privateKey
privateKey,
});

@@ -50,0 +74,0 @@ return sftp;

2

package.json
{
"name": "@passioncloud/sftp-connection",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc