Girish Ramakrishnan 7 months ago
commit
e9c7454cca
3 changed files with 114 additions and 0 deletions
  1. 57 0
      package-lock.json
  2. 18 0
      package.json
  3. 39 0
      test.js

+ 57 - 0
package-lock.json

@@ -0,0 +1,57 @@
+{
+  "name": "sftp",
+  "version": "1.0.0",
+  "lockfileVersion": 1,
+  "requires": true,
+  "dependencies": {
+    "asn1": {
+      "version": "0.2.4",
+      "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
+      "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
+      "requires": {
+        "safer-buffer": "~2.1.0"
+      }
+    },
+    "bcrypt-pbkdf": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
+      "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
+      "requires": {
+        "tweetnacl": "^0.14.3"
+      }
+    },
+    "safer-buffer": {
+      "version": "2.1.2",
+      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
+    },
+    "ssh2": {
+      "version": "0.8.2",
+      "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-0.8.2.tgz",
+      "integrity": "sha512-oaXu7faddvPFGavnLBkk0RFwLXvIzCPq6KqAC3ExlnFPAVIE1uo7pWHe9xmhNHXm+nIe7yg9qsssOm+ip2jijw==",
+      "requires": {
+        "ssh2-streams": "~0.4.2"
+      }
+    },
+    "ssh2-streams": {
+      "version": "0.4.2",
+      "resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.2.tgz",
+      "integrity": "sha512-2rSj3oTIJnbAIzR3+XwIYef9wCOVrPQZNLL+fFPPjnPxf09tKkAbgrlYgh/1qynBTz65AUOS+s1zuko4M/GKCw==",
+      "requires": {
+        "asn1": "~0.2.0",
+        "bcrypt-pbkdf": "^1.0.2",
+        "streamsearch": "~0.1.2"
+      }
+    },
+    "streamsearch": {
+      "version": "0.1.2",
+      "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
+      "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
+    },
+    "tweetnacl": {
+      "version": "0.14.5",
+      "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
+      "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
+    }
+  }
+}

+ 18 - 0
package.json

@@ -0,0 +1,18 @@
+{
+  "name": "sftp",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "ssh://git@git.girish.in:29418/girish/sftp.git"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "ssh2": "^0.8.2"
+  }
+}

+ 39 - 0
test.js

@@ -0,0 +1,39 @@
+'use strict';
+
+let Ssh2Client = require('ssh2').Client;
+
+function sftpConnect(host, username, password, callback) {
+    let conn = new Ssh2Client();
+    conn.on('error', callback);
+    conn.on('ready', function() {
+        conn.sftp(function (error, sftp) {
+            callback(error, sftp, conn);
+        });
+    }).connect({
+        host: host,
+        port: 222,
+        username: username,
+        password: password 
+    });
+}
+
+function sftpList(callback) {
+    sftpConnect(process.env.HOST, process.env.USERNAME, process.env.PASSWORD, function (error, sftp, conn) {
+        if (error) return callback(error);
+
+        sftp.readdir('.', function (error, entries) {
+            if (error) return callback(error);
+
+            sftp.end();
+            conn.end();
+console.dir(sftp);
+            callback(null, entries);
+        });
+    });
+}
+
+sftpList(function (error, entries) {
+    console.log(error);
+    console.log(entries);
+});
+