npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsftp-mlst

v1.0.9

Published

Adds MLST/MLSD support to JsFtp

Downloads

4

Readme

jsftp-mlst

Adds MLST/MLSD support to JSFtp for ftp servers that support the 'MSLT' feature.

Reference:

JSFtp Homepage

RFC 3659 - Extensions to FTP


Be sure to check that the Ftp server supports MLST/MLSD feature before using this. See How To below. MLST support by the server implies MLSD support as well.

If the Create and Modify facts are present in the MLST/MLSD server response, they are parsed and the attributes create_dt and modify_dt, respectively, are added to the entry object. create_dt and modify_dt are ISO 8601 combined date and time strings in UTC. If Create and/or Modify cannot be parsed, create_error and/or modify_error messages, as appropriate, will added to the Entry object.

Fact names are normalized to lower case in the entry objects.


Added Methods

Ftp.mlst(pathname, callback)

With the mlst method you can retrieve the MLST entry for pathname. The method accepts a callback with the signature err, entry, in which err is the error response coming from the server (usually a 4xx or 5xx error code), or an error indicating the MLST response couldn't be parsed as expected, and entry is an object containing the entry facts returned by the server.

Pathname is optional. If omitted, the server is expected to return an MLST entry for the current working directory.


"use strict";

/**
 * Example using mlst
 */

const jsftp = require("jsftp");
require("jsftp-mlst")(jsftp);

const Ftp = new jsftp({
  host: "your.ftpserver.com",
  user: "ftpusername",
  pass: "ftppassword",
});


Ftp.on("connect", function() {
  Ftp.mlst("myfile.txt", (err, result) => {
    if (err) {
      console.log(err);
    } else {
      console.log(result);
    // Prints something like
    // { pathname: '/myfile.txt',
    //   create_dt: '2017-06-14T20:06:11+00:00',
    //   create: '20170614200611',
    //   modify_dt: '2017-06-14T20:06:11+00:00',
    //   modify: '20170614200611',
    //   perm: 'adfrw',
    //   size: '2291365',
    //   type: 'file',
    //   unique: 'ca032380be1',
    //   'unix.group': '501',
    //   'unix.mode': '0644',
    //  'unix.owner': '501' }
    }

    Ftp.destroy();
  });
});
Ftp.mlsd(pathname, callback)

With the mlsd method you can retrieve the contents of the directory specified with pathname. The mlsd method accepts a callback with the signature err, entries where err is the error response coming from the server or error processing the server response, and entries is an array of entry objects containing the facts returned by the server for each item in the directory (usually includes the dir itself).

pathname is optional. If omitted, the server is expected to return the contents of the current working directory.


"use strict";

/**
 * Example using mlsd
 */

const jsftp = require("jsftp");
require("jsftp-mlst")(jsftp);

const Ftp = new jsftp({
  host: "your.ftpserver.com",
  user: "ftpusername",
  pass: "ftppassword",
});


Ftp.on("connect", function() {
  Ftp.mlsd("/", (err, entries) => {
    if (err) {
      console.log(err);
    } else {
      console.log(entries);
          // Prints something like
          // [{ pathname: 'myfile.txt',
          //   modify_dt: '2017-06-14T20:06:11+00:00',
          //   modify: '20170614200611',
          //   perm: 'adfrw',
          //   size: '2291365',
          //   type: 'file',
          //   unique: 'ca032380be1',
          //   'unix.group': '501',
          //   'unix.mode': '0644',
          //  'unix.owner': '501' },
          // { pathname: '..',
          //   modify_dt: '2017-06-14T20:06:19+00:00',
          //   modify: '20170614200619',
          //   perm: 'flcdmpe',
          //   type: 'pdir',
          //   unique: 'ca01u82148',
          //   'unix.group': '501',
          //   'unix.mode': '0700',
          //   'unix.owner': '501' },
          // { pathname: '.',
          //   modify_dt: '2017-06-14T20:06:19+00:00',
          //   modify: '20170614200619',
          //   perm: 'flcdmpe',
          //   type: 'cdir',
          //   unique: 'ca01u82148',
          //   'unix.group': '501',
          //   'unix.mode': '0700',
          //   'unix.owner': '501' }]
    }
    Ftp.destroy();
  });
});
Other Notes

OS Dependent Facts have a '.' in their names (see 'unix.xxx' facts in examples above). If you need to read them you'll have to do something like: entry['unix.mode']

MLSD/MLST implementation specifics vary across Ftp servers. The facts you receive may be quite different than the examples above.

I tried to stick to the language support and eslint config of the jsftp project for consistency.


How To Test For MLST Feature Support

The MLST feature has an extended format in the FEAT ftp command response so the hasFeat method from JsFTP doesn't properly detect it. Here's an example of my current recommendation for how to detect it:


"use strict";

/**
 * Example checking for MLST support
 */

const jsftp = require("jsftp");
require("jsftp-mlst")(jsftp);

const Ftp = new jsftp({
  host: "your.ftpserver.com",
  user: "ftpusername",
  pass: "ftppassword",
});


Ftp.on("connect", function() {
  Ftp.getFeatures((err, features) => {
    // ... IRL handle err from getFeatures here!
    if (features.some(feat => feat.startsWith("mlst"))) { // mlst needs to be lowercase here
      // server has MLST/MLSD support!
      Ftp.mlst("/", (err, entries) => {
        if (err) {
          console.log(err);
        } else {
          console.log(entries);
        }
      });
    } else {
      // server does not support MLST/MLSD
      console.log('server does not support MLST/MLSD');
    }
  });
});

Of course, you could also just call mlst or mlsd and handle the error that is passed to your callback if the server doesn't support it.