使用节点列出远程目录中的文件

时间:2022-08-09 00:09:48

I have a remote directory on 'xyz.com/myimages/'. This directory has many files in it.

我在'xyz.com/myimages/'上有一个远程目录。该目录中包含许多文件。

I would like to use my Node.js app to retrieve this list of file names from that URL (xyz.com/myimages/). I have verified that Apache is configured to permit directory indexing for this path.

我想使用我的Node.js应用程序从该URL(xyz.com/myimages/)中检索此文件名列表。我已经验证Apache已配置为允许此路径的目录索引。

How can I retrieve the file names form the URL using Node.JS?

如何使用Node.JS从URL检索文件名?

2 个解决方案

#1


If you have an SSH access you can do this like this:

如果您有SSH访问权限,可以这样做:

var exec = require('child_process').exec;

exec("ssh login@xyz.com 'ls /path/to/myimages'",
  function (error, stdout, stderr) {
    console.log('remote files: ' + stdout);
  });

#2


IMHO , Better way is to use library like https://github.com/mscdex/ssh2 . It can provide a more programatic handle to operations on the machine than exec .

恕我直言,更好的方法是使用像https://github.com/mscdex/ssh2这样的库。它可以为机器上的操作提供比exec更多的程序设计。

#1


If you have an SSH access you can do this like this:

如果您有SSH访问权限,可以这样做:

var exec = require('child_process').exec;

exec("ssh login@xyz.com 'ls /path/to/myimages'",
  function (error, stdout, stderr) {
    console.log('remote files: ' + stdout);
  });

#2


IMHO , Better way is to use library like https://github.com/mscdex/ssh2 . It can provide a more programatic handle to operations on the machine than exec .

恕我直言,更好的方法是使用像https://github.com/mscdex/ssh2这样的库。它可以为机器上的操作提供比exec更多的程序设计。