New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ftp_demo

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftp_demo - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

lib/foo.txt

97

lib/ftpDemo.js
/**
* Created by zy8 on 2017/2/28.
*/
const ftp = require('ftp');
const Client = require('ftp');
var fs = require('fs');
let _options;
module.exports = {

@@ -11,6 +13,5 @@ /**

*/
initClient(options){
return new Promise(function (resolve, reject) {
resolve(1);
});
setOptions(options) {
_options = options;
},

@@ -20,20 +21,90 @@

* upload
* @param client
* @returns {*}
*/
upload(client){
*/ //
upload(localPath, remotePath){
return new Promise(function (resolve, reject) {
client = getClient();
client.on('ready', function () {
client.put(localPath, remotePath, function (err) {
if (err) {
return reject(err);
}
client.end();
resolve();
});
});
client.connect(_options);
});
},
/**
* download
* @param client
* @returns {*}
*/
download(client){
*/ //'foo.local-copy.txt'
download(localPath, remotePath){
//set ready 事件
return new Promise(function (resolve, reject) {
client = getClient();
client.on('ready', function () {
client.get(remotePath, function (err, stream) {
if (err) {
return reject(err);
}
stream.once('close', function () {
client.end();
});
stream.pipe(fs.createWriteStream(localPath));
});
});
client.connect(_options);
resolve();
});
},
pwd(){
return new Promise(function (resolve, reject) {
client = getClient();
client.on('ready', function () {
client.pwd(function (err, cwd) {
if (err) {
return reject(err)
}
console.log(cwd);
client.end();
resolve(cwd);
});
});
client.connect(_options);
});
},
list(remotePath){
return new Promise(function (resolve, reject) {
client = getClient();
client.on('ready', function () {
client.list(remotePath, function (err, list) {
if (err) {
return reject(err)
}
console.log(list);
client.end();
resolve(list);
});
});
client.connect(_options);
});
},
};
var getClient = function(){
const client = new Client();
client.on('greeting', function (msg) {
console.log('msg is ' + msg);
});
client.on('error', function (err) {
console.log('err is ' + err);
});
return client;
};
/**
* Created by zy8 on 2017/2/28.
*/
console.log('hello');
const co = require('co');
const ftpDemo = require('./lib/ftpDemo');
co(function *() {
const options = {
host: '10.0.60.95',
user: 'ftp_xiaowei',
password: 'sxw000393'
};
ftpDemo.setOptions(options); // set options
const pwd = yield ftpDemo.pwd();
//upload
const localPath = './txt/foo.txt';
const remotePath = pwd + '/new_foo.txt';
yield ftpDemo.upload(localPath, remotePath);
yield ftpDemo.list(pwd);
//download
yield ftpDemo.download(localPath + Date.now(), remotePath);
}).catch(error);
function error(err) {
console.log(err.message);
}
// ftpDemo.initClient(options)
// .then(function () {
// return ftpDemo.list();
// // return ftpDemo.upload('foo.txt', 'foo.remote-copy.txt');
// })
// .then(function () {
//
//
// // return ftpDemo.download('foo1.txt', 'foo.remote-copy.txt');
// })
// .catch(function (err) {
// console.log('err' + err);
// });
// var Client = require('ftp');
//
// var c = new Client();
// c.on('ready', function () {
// console.log('ready');
// c.list(function (err, list) {
// if (err) throw err;
// console.dir(list);
// c.end();
// });
// });
// connect to localhost:21 as anonymous
// c.connect({
// host: '10.0.60.95',
// user: 'ftp1',
// password: '123456'
// });

3

package.json
{
"name": "ftp_demo",
"version": "0.1.2",
"version": "0.1.3",
"description": "use ftp demo",

@@ -9,2 +9,3 @@ "main": "main.js",

"dependencies": {
"co": "^4.6.0",
"ftp": "^0.3.10"

@@ -11,0 +12,0 @@ },

@@ -19,7 +19,7 @@

添加允许登录的用户
添加禁止登录的用户
userlist_enable=YES(使用userlist)
userlist_deny=NO
userlist_deny=YES

@@ -36,2 +36,8 @@ userlist_file=/etc/vsftpd/vsftpd.user_list (指定userlist的文件目录)

其他(必须做)
pasv_enable=YES
pam_service_name=vsftpd
5. 新建vsftpd.user_list目录并添加步骤3中创建的用户到该文件, 新建chroot_list目录并添加步骤3中创建的用户到该文件

@@ -38,0 +44,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc