Friday, 28 April 2017

Download file over FTP using vinyl-ftp

A.t.m. I'm trying to download a file over FTP from a server using Vinyl-FTP. At some point in the download process it stops with the following error:

{ Error: EACCES: permission denied, open '/Users/serverFile.TXT'
    at Error (native)
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/Users/serverFile.TXT' }

This is my code:

const log = require('../lib/application-log');
const ftp = require('vinyl-ftp');
const fs = require('vinyl-fs');
const fileDumpPath = require('../lib/rootDir')('data/dumps');
const config = require('../constants/config');

const conn = ftp.create({
    host: config.FTP_SERVER,
    user: config.FTP_USER,
    password: config.FTP_PASS,
    log
});

const serverFilePath = 'serverFile.TXT';

try {
    conn.src(serverFilePath, {base: '.', buffer: true})
        .pipe(fs.dest('./data'))
        .on('error', (e) => {
            log(e);
        })
} catch (e) {
    log(e);
}

It seems that it tries to access my local file system in the /Users folder (OSX). I don't get why it does that. Does anyone have an idea on how to properly configure Vinyl-FTP for downloading over FTP?

I figured it may be related to the 'base'-option in the conn.src-function. The API for this option is described as follows:

base: Set as file.base, default is glob beginning. This is used to determine the file names when saving in .dest().

But I don't really get this. More info can be found here: https://github.com/morris/vinyl-ftp#connsrc-globs-options--stream



via nicoes

No comments:

Post a Comment