mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 246 forks source link

list #188

Open ghost opened 7 years ago

ghost commented 7 years ago

let c = Clinet();

c.on('ready', function() { c.list(path, function(err, list) { if (err) throw err; console.log(list); }); });

[ '-rw-r--r-- 1 oinstall 65536 Jul 25 15:01 csxl20170724.dmp', 'drwxr-xr-x 2 oinstall 4096 Jul 25 14:33 log' ]

why the list() return an array of strings, not object?

ghost commented 7 years ago

no people?

etienne678 commented 6 years ago

same issue here. strangely it only happens on one ftp server and not on another. i suspect it has something to do with different FTP Server systems. most of them return an object, but some do in fact return a string.

dreamdevil00 commented 6 years ago

Just a suggestion. I think you should offer your ftp server related information

icetee commented 6 years ago

Your server no response owner or group permission name and the parser can't process it. Which do you use server and operating system?

eli8levit commented 6 years ago

same issue...It works great at work on windows but not on my mac. Can't get response of list method

Rolandisimo commented 5 years ago

Still encountering the same issue. Tried on Ubuntu and MacOS.

Rolandisimo commented 5 years ago

If anyone stumbles upon this issue, this is how I resolved it. However, I am not sure that this solution will work for every FTP server.

Code is in Typescript:

enum ListingType {
  Directory = "d",
  File = "-",
  Symlink = "l",
}

enum SpecialListingType {
  Directory = "*DIR",
  File = "*STMF",
  Symlink = "l",
}

const getFtpListingElement = (entry: string | ListingElement): ListingElement => {
  if (typeof entry !== "string") {
    return entry;
  }

  // `entry` is something like "OWNER 1234 12/12/19 18:19:20 *SFTIM Path/To/The/FileOrFolder/Location"
  const [
    owner,
    size,
    lastDateModified,
    lastTimeModified,
    type, // Afaik can be of 3 types - *DIR (dir), *SFTIM (file) or something else that I haven't encountered but which would stand for Symlink
    name,
  ] = entry
    .split(" ")
    .map((part) => part.trim())
    .filter(Boolean)
  ;

  return {
    owner,
    group: owner,
    size,
    date: new Date(`${lastDateModified} ${lastTimeModified}`),
    name,
    type: getListingType(type as SpecialListingType), // Each type above corresponds to a type character mentioned in the docs - d (dir), - (file), l (symlink)
  };
};

const listings = (await ftp.list("/my/path")).map(getFtpListingElement);

The problem with this is that there is no data about permissions. At least not in my case. Let me know if this works for you.

OmegaZhou commented 4 years ago

I find the problem only when I cancel the execute permission of the group. But I don't know why it can cause the problem