1.0.1 • Published 3 years ago
ftp-for-node v1.0.1
Ftp-For-Node
A basic Ftp and Explicit FTPS client and server for nodejs that helps to make the transfer of files easier.
To Install
npm install --save ftp-for-node
Examples
Client
//Import
const FtpClient = require("ftp-for-node/client");
const ftp = new FtpClient();
//Specify the available port for data-channel
ftp.dataChannel.port = 3000;
//For RETR
ftp.localSite = "E:\\project\\ftp-for-node\\";
//For Authorization - optional for anonymous
ftp.user = "abc";
ftp.password = "123";
//"connect" - Listener
ftp.on("connect",(code,msg)=>{
console.log(code,msg);
ftp.PORT("127,0,0,1,11,184",(err,msg)=>{
console.log(err,msg);
})
ftp.PWD((err,pwd)=>{
console.log(err,pwd);
})
ftp.LIST(null,(err,msg)=>{
console.log(err,msg)
})
ftp.QUIT((err,msg)=>{
console.log(err,msg);
})
})
//Init Client
ftp.connect();Server
//Import
const FtpServer = require("ftp-for-node/server");
const server = new FtpServer();
//Mandatory-in case no userDetails exists - anonymous
server.defaultPWD = "E:/nodefiles";
//Array of users who can access - authorized use
server.userDetails = [{name:"abc",password:"123",pwd:"pathname to the folder"}];
//Init
server.initiateFtpServer();Client Features
The client supports properties like :
Specify the available port for data-channel
ftp.dataChannel.port = "number"
For local file reference
ftp.localSite = "absolute pathname";
For Authorization - optional for anonymous
- ftp.user = "string";
- ftp.password = "string";
For AUTH
- ftp.secureOptions.key = fs.readFileSync('key.pem');
- ftp.secureOptions.cert = fs.readFileSync('cert.pem');
Control Channel port and address
- port = "number"
- address = "string"
How to Use the methods ?
Format :
FtpClient.method([arg],calback:function(err,msg))The client supports methods like :
PORT("h1,h2,h3,h4,h5,p1,p2",callback(err,msg))
To send the port number of data-channel for active mode.PASV(callback(err,msg))
Convert to passive modeLIST(pathname|null,callback(err,msg))
To list the files in PWDNSLT(pathname|null,callback(err,msg))
To list the file name in PWDSTOR(pathname,callback(err,msg))
To Store the local files in serverRETR(pathname,callback(err,msg))
To retrieve files from serverAPPE(pathname,callback(err,msg))
To Append the local files in serverSTOU(pathname,callback(err,msg))
To Store with unique name the local files in serverRMD(pathname,callback(err,msg))
Remove folderMKD(pathname,callback(err,msg))
Make folderCWD(pathname,callback(err,msg))
Change wprking directoryPWD(callback(err,msg))
Return present directory nameTYPE("I"|"A",callback(err,msg))
Change TypeSYST(callback(err,msg))
Return System infoSTAT(string|null,callback(err,msg))
Return Current StateQUIT(callback(err,msg))
Close Control ChannelAUTH('tls',callback(err,msg))
Explicit Security using TLSServer Features
The client supports properties like :
The authorized user details - Optional
- userDetails = [{name:"string" , password:"string" , pwd:string }...]
The local connection details for control channel
- localPort = "number" | default : 21
- localAddress = "string" | default : localhost
Passive connection details
- passive = { active : "boolean" | default : true , address : "string" | default : "127.0.0.1" , port : "number" | default : 40000 }
For AUTH
- ftp.secureOptions.key = fs.readFileSync('key.pem');
- ftp.secureOptions.cert = fs.readFileSync('cert.pem');
For anonymous users - mandatory
- defaultPWD = "string"
TO INIT