A basic Ftp and Explicit FTPS client and server for nodejs that helps to make the transfer of files easier.
npm install --save ftp-for-node
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();
The client supports properties like :
Specify the available port for data-channel
For local file reference
For Authorization - optional for anonymous
For AUTH
Control Channel port and address
Format :
FtpClient.method([arg],calback:function(err,msg))
The client supports methods like :
To send the port number of data-channel for active mode.
Convert to passive mode
To list the files in PWD
To list the file name in PWD
To Store the local files in server
To retrieve files from server
To Append the local files in server
To Store with unique name the local files in server
Remove folder
Make folder
Change wprking directory
Return present directory name
Change Type
Return System info
Return Current State
Close Control Channel
Explicit Security using TLS
The client supports properties like :
The authorized user details - Optional
The local connection details for control channel
Passive connection details
For AUTH
For anonymous users - mandatory
TO INIT