Gathering detailed insights and metrics for jasonftp
Gathering detailed insights and metrics for jasonftp
Gathering detailed insights and metrics for jasonftp
Gathering detailed insights and metrics for jasonftp
npm install jasonftp
Updated `raw` API
Published on 08 Jun 2017
Bugfix release
Published on 20 Sept 2016
Fixed error when reading some remote MS-DOS folder listings
Published on 16 Nov 2015
Drop compatibility for Node 0.8
Published on 07 Feb 2015
v1.3.9
Published on 23 Dec 2014
Fix for simultaneous PASV requests
Published on 11 Oct 2014
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
809 Stars
416 Commits
153 Forks
17 Watching
71 Branches
26 Contributors
Updated on 16 Nov 2024
JavaScript (88.71%)
Dockerfile (5.11%)
Makefile (4.16%)
Shell (2.01%)
Cumulative downloads
Total Downloads
Last day
166.7%
16
Compared to previous day
Last week
132.8%
156
Compared to previous week
Last month
35.3%
537
Compared to previous month
Last year
142.3%
5,131
Compared to previous year
A client FTP library for NodeJS that focuses on correctness, clarity and conciseness. It doesn't get in the way and plays nice with streaming APIs.
1const jsftp = require("jsftp"); 2 3const Ftp = new jsftp({ 4 host: "myserver.com", 5 port: 3331, // defaults to 21 6 user: "user", // defaults to "anonymous" 7 pass: "1234" // defaults to "@anonymous" 8});
jsftp gives you access to all the raw commands of the FTP protocol in form of
methods in the Ftp
object. It also provides several convenience methods for
actions that require complex chains of commands (e.g. uploading and retrieving
files, passive operations), as shown below.
When raw commands succeed they always pass the response of the server to the
callback, in the form of an object that contains two properties: code
, which
is the response code of the FTP operation, and text
, which is the complete
text of the response.
Raw (or native) commands are accessible in the form Ftp.raw(command, params, callback)
Thus, a command like QUIT
will be called like this:
1Ftp.raw("quit", (err, data) => { 2 if (err) { 3 return console.error(err); 4 } 5 6 console.log("Bye!"); 7});
and a command like MKD
(make directory), which accepts parameters, looks like
this:
1Ftp.raw("mkd", "/new_dir", (err, data) => { 2 if (err) { 3 return console.error(err); 4 } 5 console.log(data.text); // Show the FTP response text to the user 6 console.log(data.code); // Show the FTP response code to the user 7});
options
is an object with the following properties:1{ 2 host: 'localhost', // Host name for the current FTP server. 3 port: 3333, // Port number for the current FTP server (defaults to 21). 4 user: 'user', // Username 5 pass: 'pass', // Password 6 createSocket: ({port, host}, firstAction) => { 7 return net.createConnection({port, host}, firstAction); 8 }, // function that creates the socket, default uses net.createConnection 9}
options.createSocket
could be used to implement a proxy for the ftp socket, e.g. socksv51const {SocksClient} = require('socks'); 2const ftp = new Ffp({ 3 host: 'localhost', 4 port: 3333, 5 user: 'user', 6 pass: 'password', 7 createSocket: ({port, host}, firstAction) => { 8 return SocksClient.createConnection({ 9 proxy: { 10 ipaddress: '159.203.75.200' 11 port: 1080, 12 type: 5 13 }, 14 15 command: 'connect', 16 17 destination: { 18 host, 19 port 20 } 21 }) 22 } 23})
Creates a new Ftp instance.
Host name for the current FTP server.
Port number for the current FTP server (defaults to 21).
NodeJS socket for the current FTP server.
Array of feature names for the current FTP server. It is generated when the user
authenticates with the auth
method.
Contains the system identification string for the remote FTP server.
With the raw
method you can send any FTP command to the server. The method
accepts a callback with the signature err, data
, in which err
is the error
response coming from the server (usually a 4xx or 5xx error code) and the data
is an object that contains two properties: code
and text
. code
is an
integer indicating the response code of the response and text
is the response
string itself.
Authenticates the user with the given username and password. If null or empty
values are passed for those, auth
will use anonymous credentials. callback
will be called with the response text in case of successful login or with an
error as a first parameter, in normal Node fashion.
Lists information about files or directories and yields an array of file objects
with parsed file properties to the callback
. You should use this function
instead of stat
or list
in case you need to do something with the individual
file properties.
1ftp.ls(".", (err, res) => { 2 res.forEach(file => console.log(file.name)); 3});
Lists filePath
contents using a passive connection. Calls callback with a
string containing the directory contents in long list format.
1ftp.list(remoteCWD, (err, res) => { 2 console.log(res); 3 // Prints something like 4 // -rw-r--r-- 1 sergi staff 4 Jun 03 09:32 testfile1.txt 5 // -rw-r--r-- 1 sergi staff 4 Jun 03 09:31 testfile2.txt 6 // -rw-r--r-- 1 sergi staff 0 May 29 13:05 testfile3.txt 7 // ... 8});
Gives back a paused socket with the file contents ready to be streamed, or calls the callback with an error if not successful.
1var str = ""; // Will store the contents of the file 2ftp.get("remote/path/file.txt", (err, socket) => { 3 if (err) { 4 return; 5 } 6 7 socket.on("data", d => { 8 str += d.toString(); 9 }); 10 11 socket.on("close", err => { 12 if (hadErr) { 13 console.error("There was an error retrieving the file."); 14 } 15 }); 16 17 socket.resume(); 18});
Stores the remote file directly in the given local path.
1ftp.get("remote/file.txt", "local/file.txt", err => { 2 if (hadErr) { 3 return console.error("There was an error retrieving the file."); 4 } 5 console.log("File copied successfully!"); 6});
Uploads a file to filePath
. It accepts a string with the local path for the
file, a Buffer
, or a Readable stream as a source
parameter.
1ftp.put(buffer, "path/to/remote/file.txt", err => { 2 if (!err) { 3 console.log("File transferred successfully!"); 4 } 5});
Renames a file in the server. from
and to
are both filepaths.
1ftp.rename(from, to, (err, res) => { 2 if (!err) { 3 console.log("Renaming successful!"); 4 } 5});
Refreshes the interval thats keep the server connection active. wait
is an
optional time period (in milliseconds) to wait between intervals.
You can find more usage examples in the unit tests. This documentation will grow as jsftp evolves.
npm install jsftp
JSFtp tests against ProFTPD by default. To accomplish that, it uses a Docker set-up, so you'll need Docker installed in your machine in order to run tests.
Please note that the first time you run the tests it will take a while, given that it has to download, configure and run the containerized ProFTPD server.
To run tests and coverage reports:
npm test
...
43 passing (10s)
|-----------|----------|----------|----------|----------|----------------|
|File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
|-----------|----------|----------|----------|----------|----------------|
|All files | 86.47 | 73.17 | 95.45 | 86.47 | |
|jsftp | 100 | 100 | 100 | 100 | |
| index.js | 100 | 100 | 100 | 100 | |
|jsftp/lib | 86.43 | 73.17 | 95.45 | 86.43 | |
| jsftp.js | 86.43 | 73.17 | 95.45 | 86.43 |... 722,724,733 |
|-----------|----------|----------|----------|----------|----------------|
See LICENSE.
No vulnerabilities found.
Reason
no vulnerabilities detected
Reason
tokens are read-only in GitHub workflows
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 7
Details
Reason
GitHub code reviews found for 4 commits out of the last 30 -- score normalized to 1
Details
Reason
0 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 0
Reason
no badge detected
Reason
no update tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Reason
project is not fuzzed
Score
Last Scanned on 2022-08-15
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More