atinux / node-ftps

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

FTP over TLS #55

Open nomanmaqsood opened 7 years ago

nomanmaqsood commented 7 years ago

Hello,

I am trying to connect FTP server which is over tls,

but I am getting this error

null { error: 'ls: Fatal error: max-retries exceeded\n', data: '' }

Here is my code

var FTPS = require('ftps'); var ftps = new FTPS({ host: "", username: '', password: '*****', port: 990, protocol: 'sftp', sshKeyPath: "1.ssh" });

ftps.ls().exec(function (err, res) { if (err || res.error) return console.log('Error', (err || res.error)); console.log(res); });

ftps.addFile('test.text').exec(function (err, res) { if (err || res.error) return console.log('Error on adding file:', (err || res.error)); console.log('File added on server!'); });

Please guide me, the fault is in my code or on ftp server or in the library ? https://ibb.co/fibpAF

nomanmaqsood commented 7 years ago

Here is my code

var FTPS = require('ftps'); var ftps = new FTPS({ host: "", username: '', password: '*****', port: 990, protocol: 'sftp', sshKeyPath: "1.ssh" });

ftps.ls().exec(function (err, res) { if (err || res.error) return console.log('Error', (err || res.error)); console.log(res); });

ftps.addFile('test.text').exec(function (err, res) { if (err || res.error) return console.log('Error on adding file:', (err || res.error)); console.log('File added on server!'); });

Please guide me, the fault is in my code or on ftp server or in the library ?

atinux commented 7 years ago

Can you try to use lftp command directly and see if you can connect? See https://stackoverflow.com/questions/23900071/how-do-i-get-lftp-to-use-ssl-tls-security-mechanism-from-the-command-line

nomanmaqsood commented 7 years ago

@Atinux I tried to connect using lftp from terminal, and it worked fine, here is the screenshot https://ibb.co/hf3Y5F.

I set the lftp to set ssl:verify-certificate no and it worked Now how to it with your library ?

nomanmaqsood commented 7 years ago

@Atinux Its been 3 days I have posted this problem.

atinux commented 7 years ago

Hi @NomanMaqsood

I have been in holidays for the last 4 days, please remember I'm maintaining this project for free :)

Can you try to use the additionalLftpCommands property to add these specific commands?

additionalLftpCommands: 'set ssl:verify-certificate no; set ssl-allow true; set passive-mode yes'

Please take a look at https://github.com/Atinux/node-ftps/blob/master/index.js#L106 to understand more how it works.

nomanmaqsood commented 7 years ago

tried this as well, but did not work

atinux commented 7 years ago

@NomanMaqsood do you mind sending me an email (look on my Github profile) with the details to connect to this specific server?

d0b1010r commented 7 years ago

@NomanMaqsood I just successfully connected to an ftp server over ssl:

var FTPS = require('ftps');
var ftps = new FTPS({
    host: 'xx',
    username: 'xx',
    password: 'xx',
    protocol: 'ftp', // <----- !
    port: 5021,
    additionalLftpCommands: [
        'set ssl-allow true',
        'set ssl:verify-certificate no',
        'set passive-mode yes'
    ].join(';'),
});
ftps.ls().exec(console.log);
kucherenkovova commented 6 years ago
var FTPS = require('ftps');
var ftps = new FTPS({
    host: 'xx',
    username: 'xx',
    password: 'xx',
    protocol: 'ftps',
    additionalLftpCommands: [
        'set ssl-allow true',
        'set ssl:verify-certificate no',
        'set passive-mode yes'
    ].join(';'),
});
ftps.ls().exec(console.log);

worked for me

communque commented 6 years ago

So I'm able to connect using lftp in powershell, but not when using node ftps on Windows.

Here's the powershell version: lftp -u 'uid,pwd' -e 'set ftp:ssl-allow 0; ls /path/to/get;' -p 21 ftp.domain.com Works perfectly. Returns the file directory.

Here's the node version

var FTPS=require("ftps");
var Options={
    host: ftp.domain.com,
    username: "uid",
    password: "pwd",
    port: 21,
    escape: false,//or true  Tried both
    retries: 2,
    additionalLftpCommands: "set ftp:ssl-allow 0; ls /path/to/get"
};
var ftps = new FTPS(Options);
ftps.exec(function(Err,Rslts){
    if(Err){
        console.log(Err);
    }else{
        console.log(Rslts);
    }
});

Returns the error "ls: ls /path/to/get: not connected\n"