node-ftp icon indicating copy to clipboard operation
node-ftp copied to clipboard

list

Open ghost opened this issue 8 years ago • 8 comments

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 avatar Jul 25 '17 09:07 ghost

no people?

ghost avatar Jul 26 '17 05:07 ghost

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.

etienne678 avatar Oct 13 '17 10:10 etienne678

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

dreamdevil00 avatar Nov 13 '17 02:11 dreamdevil00

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

icetee avatar Dec 05 '17 10:12 icetee

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

eli8levit avatar Feb 20 '18 08:02 eli8levit

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

Rolandisimo avatar Aug 27 '19 10:08 Rolandisimo

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.

Rolandisimo avatar Aug 28 '19 08:08 Rolandisimo

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

OmegaZhou avatar Sep 28 '19 13:09 OmegaZhou