atinux / node-ftps

FTP, FTPS and SFTP client for node.js, mainly a lftp wrapper.
MIT License
203 stars 57 forks source link

Cannot get file list from ftp using ls() #39

Closed neeraj87 closed 7 years ago

neeraj87 commented 7 years ago

I have FTP server which has a folder with a bunch of images in it. I do not know the image names. I want to access all the image files from that FTP folder and read them as base64 format one by one, so I can upload them to some other destination. I am trying to get the list of files in the ftp using the ls() method but run into the error below.

var ftps = new FTPS({
        host: 'ftp://mydomain.com/', // required
        username: 'username', // required
        password: 'password', // required
        protocol: 'ftp', // optional, values : 'ftp', 'sftp', 'ftps',... default is 'ftp'
        // protocol is added on beginning of host, ex : sftp://domain.com in this case
        port: 22, // optional
        // port is added to the end of the host, ex: sftp://domain.com:22 in this case
        escape: true, // optional, used for escaping shell characters (space, $, etc.), default: true
        retries: 2, // Optional, defaults to 1 (1 = no retries, 0 = unlimited retries)
        timeout: 10,
        requiresPassword: true, // Optional, defaults to true
        autoConfirm: true, // Optional, is used to auto confirm ssl questions on sftp or fish protocols, defaults to false
        cwd: '' // Optional, defaults to the directory from where the script is executed
    });

    ftps.ls().exec(function(err, res){
        if(err || res.error){
            console.log('-------- error');
            return console.log('Error getting file list:', (err || res.error));
        }
        console.log('------- response: ' + res);
    });

I get the following error:

Error getting file list: { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }

atinux commented 7 years ago

node-ftps is a lftp wrapper, can you check if you have lftp installed on your computer?

neeraj87 commented 7 years ago

lftp was not installed on my computer. I just installed it, but now it gives the following error:

Error getting file list: cd: Fatal error: Certificate verification: subjectAltName does not match ‘mydomain.com’

Another question I had was that I am making this node.js application for some clients to use but this means all of them have to have lftp installed on their computers. The end users for my app are not so tech savvy people, that's why this tool is being made for them where they can just give their ftp credentials and get the image import done.

atinux commented 7 years ago

For the SSL error, it's because the certificate is not valid for the domain. Try to use the autoConfirm: true option.

What you can do is to create an API based on it and call your API from your application to avoid installing lftp on their computers, or wrapping it in your application and calling the binary directly.

neeraj87 commented 7 years ago

I have made the autoConfirm: true (in the code given above). But it is still showing this error.

atinux commented 7 years ago

So this is definitely an error from your SSL certificate on your server, not from node-ftps

neeraj87 commented 7 years ago

Oh ok, I will diagnose the error and see if anything is missing from my side. Thanks for the help, I really appreciate it.

jarodium commented 7 years ago

Hello @neeraj87 , did you manage to solve this?