Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
jsftp is a lightweight FTP client for Node.js that allows you to interact with FTP servers. It supports a variety of FTP operations such as uploading, downloading, renaming, and deleting files, as well as creating and removing directories.
Connecting to an FTP server
This code demonstrates how to connect to an FTP server using jsftp. You need to provide the host, username, and password for the FTP server.
const JSFtp = require('jsftp');
const ftp = new JSFtp({
host: 'ftp.example.com',
user: 'username',
pass: 'password'
});
ftp.auth('username', 'password', (err, res) => {
if (err) return console.error(err);
console.log('Connected to FTP server');
});
Uploading a file
This code demonstrates how to upload a file from the local filesystem to the FTP server using jsftp.
ftp.put('local/path/to/file.txt', 'remote/path/to/file.txt', err => {
if (err) return console.error(err);
console.log('File uploaded successfully');
});
Downloading a file
This code demonstrates how to download a file from the FTP server to the local filesystem using jsftp.
ftp.get('remote/path/to/file.txt', 'local/path/to/file.txt', err => {
if (err) return console.error(err);
console.log('File downloaded successfully');
});
Listing files in a directory
This code demonstrates how to list files in a directory on the FTP server using jsftp.
ftp.ls('remote/path/to/directory', (err, res) => {
if (err) return console.error(err);
res.forEach(file => {
console.log(file.name);
});
});
Deleting a file
This code demonstrates how to delete a file on the FTP server using jsftp.
ftp.raw('DELE', 'remote/path/to/file.txt', (err, res) => {
if (err) return console.error(err);
console.log('File deleted successfully');
});
The 'ftp' package is another FTP client for Node.js. It provides similar functionalities to jsftp, such as connecting to an FTP server, uploading, downloading, and deleting files. However, 'ftp' is known for its simplicity and ease of use, making it a good choice for basic FTP operations.
The 'promise-ftp' package is a promise-based FTP client for Node.js. It offers similar functionalities to jsftp but uses promises instead of callbacks, which can make the code cleaner and easier to manage, especially for complex workflows.
The 'ssh2-sftp-client' package is an SFTP client for Node.js. While it focuses on SFTP rather than FTP, it provides similar functionalities such as uploading, downloading, and managing files on a server. It is built on top of the 'ssh2' package and is known for its reliability and performance.
jsftp is a client FTP library for NodeJS that focuses on correctness, clarity and conciseness. It doesn't get in the middle of the user intentions, and plays nice with streaming APIs.
jsftp gives the user access to all the raw commands of FTP 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). When 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["desired_command"](params, callback)
Thus, a command like QUIT
will be called like
Ftp.raw.quit(function(err, data) {
if (err) return console.error(err);
console.log("Bye!");
});
and a command like MKD
, which accepts parameters, will look like
Ftp.raw.mkd("/new_dir", function(err, data) {
if (err) return console.error(err);
console.log(data.text); // Presenting the FTP response text to the user
console.log(data.code); // Presenting the FTP response code to the user
});
var Ftp = require("jsftp");
var ftp = new Ftp({
host: "myhost.com",
user: "johndoe",
port: 3334, // Defaults to 21
pass: "12345"
});
// Retrieve a file in the remote server. When the file has been retrieved,
// the callback will be called with `data` being the Buffer with the
// contents of the file.
// `ftp.get` is a convenience method. In this case, it hides the actual
// complexity of setting up passive mode and retrieving files. Keep in mind that
// this will buffer the contents of the file in memory before transmitting them. For a streaming, non-buffering solution please use `getGetSocket`.
ftp.get("/folder/file.ext", function(err, data) {
if (err)
return console.error(err);
// Do something with the buffer
doSomething(data);
// We can use raw FTP commands directly as well. In this case we use FTP
// 'QUIT' method, which accepts no parameters and returns the farewell
// message from the server
ftp.raw.quit(function(err, res) {
if (err)
return console.error(err);
console.log("FTP session finalized! See you soon!");
});
});
// Create a directory
ftp.raw.mkd("/example_dir", function(err, data) {
if (err) return console.error(err);
console.log(data.text);
});
// Delete a directory
ftp.raw.rmd("/example_dir", function(err, data) {
if (err) return console.error(err);
console.log(data.text);
});
// Listing a directory
ftp.ls("/example_dir", function(err, files){
if (err) return console.error(err);
console.log(files); // Contains an array of file objects
});
// Retrieving a file using streams
ftp.getGetSocket("/test_dir/testfile.txt"), function(err, readable) {
if (err) return console.error(err);
var pieces = [];
// `readable` is a stream, so we can attach events to it now
readable.on("data", function(p) { pieces.push(p); });
readable.on("close", function(err) {
if (err) return console.error(new Error("readable connection error"));
// `Ftp._concat` is an internal method used to concatenate buffers, it
// is used here only for illustration purposes.
console.log(Ftp._concat(pieces)); // print the contents of the file
});
// The readable stream is already paused, we have to resume it so it can
// start streaming.
readable.resume();
});
// Storing a file in the FTP server, using streams
var originalData = Fs.createReadStream("sourceFile.txt"));
originalData.pause();
ftp.getPutSocket("/remote_folder/sourceFileCopy.txt"), function(err, socket) {
if (err) return console.error(err);
originalData.pipe(socket); // Transfer from source to the remote file
originalData.resume();
});
You can find more usage examples in the unit tests. This documentation will grow as jsftp evolves.
Host name for the current FTP server.
Port number for the current FTP server (defaults to 21).
NodeJS socket for the current FTP server.
features
is an array of feature names for the current FTP server. It is
generated when the user authenticates with the auth
method.
All the standard FTP commands are available under the raw
namespace. These
commands might accept parameters or not, but they always accept 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 filePath
contents using a passive connection.
Downloads filePath
from the server.
Uploads a file to filePath
. It accepts a buffer
parameter that will be
written in the remote file.
Renames a file in the server. from
and to
are both filepaths.
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.
Refreshes the interval thats keep the server connection active. There is no need to call this method since it is taken care internally
With NPM:
npm install jsftp
From GitHub:
git clone https://github.com/sergi/jsftp.git
To run the tests:
npm test
Please note that for now the unit tests require python because the FTP server used is written in python.
0.5.8
0.5.7
0.5.6
0.5.5
See LICENSE.
FAQs
A sane FTP client implementation for NodeJS
The npm package jsftp receives a total of 172,850 weekly downloads. As such, jsftp popularity was classified as popular.
We found that jsftp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.