Open jayant-simpragma opened 8 years ago
Can you provide the sample code here?
I am getting the same error. Here is my code:
var Client = require('ftp');
var fs = require('fs');
var fileName = 'file.pdf';
var fileLocation = '/myFiles';
var ftpClient = new Client();
var options = {
host: 'host',
user: 'user',
password: 'password',
connTimeout: 15000,
secure: true,
secureOptions: {
rejectUnauthorized: false
}
};
ftpClient.connect(options);
console.log('Connecting to ftp server ...');
ftpClient.on('ready', function() {
console.log('Successfully connected to FTP server');
console.log('----------------------------------------------------------------------------------------');
getFile();
});
ftpClient.on('error', function(error) {
console.log('Unable to connect to FTP server :', error);
});
ftpClient.on('end', function() {
console.log('Connection closed');
});
function getFile() {
ftpClient.get(fileLocation + '/' + fileName, function(err, stream) {
if (err) {
console.log('Error while getting the file :', err)
} else {
stream.pipe(fs.createWriteStream('output.pdf'));
stream.once('close', function() {
console.log('Stream ended');
});
}
});
}
I get the following error occasionally when the file starts to download from the FTP server. This error stops the whole process and I usually have to trigger it again (and the file downloads without any problem). It doesn't reach the error handler as well.
node-ftp version: 0.3.10
I would like to know the cause of this occasional error and the way to catch/handle it in the code.