jsftp icon indicating copy to clipboard operation
jsftp copied to clipboard

Uploading files does not work

Open alextes opened this issue 8 years ago • 6 comments

Using Ubuntu Yakkety and vsftpd 3.0.3-7 uploading files does not work. Tried with Node 8, 6 and 4. Just executing auth works fine. Making a put fails with the following error:

{ Error: 425 Failed to establish connection.
    at Ftp.parse (/Users/alexander/code/notepad/js/node_modules/jsftp/lib/jsftp.js:337:11)
    at Ftp.parseResponse (/Users/alexander/code/notepad/js/node_modules/jsftp/lib/jsftp.js:216:8)
    at Stream.<anonymous> (/Users/alexander/code/notepad/js/node_modules/jsftp/lib/jsftp.js:156:10)
    at emitOne (events.js:96:13)
    at Stream.emit (events.js:188:7)
    at ResponseParser.reemit (/Users/alexander/code/notepad/js/node_modules/duplexer/index.js:70:25)
    at emitOne (events.js:96:13)
    at ResponseParser.emit (events.js:188:7)
    at readableAddChunk (/Users/alexander/code/notepad/js/node_modules/ftp-response-parser/node_modules/readable-stream/lib/_stream_readable.js:195:16)
    at ResponseParser.Readable.push (/Users/alexander/code/notepad/js/node_modules/ftp-response-parser/node_modules/readable-stream/lib/_stream_readable.js:162:10) code: 425 }

alextes avatar Jun 05 '17 12:06 alextes

Are you able to make a test that fails with your use case?

sergi avatar Jun 08 '17 10:06 sergi

Was hoping to get a way with not including one 😛. Here you go @sergi :

  1. set up Ubuntu Yakkety
  2. install vsftpd
  3. configure ftp writing to be allowed
  4. restart vsftpd
  5. run the following node script
const fs = require('fs');
const JSFtp = require("jsftp");

const ftp = new JSFtp({
  host: "51.15.68.200",
  user: "ftpuser", // defaults to "anonymous"
  pass: "NYTimes", // defaults to "@anonymous"
  debugMode: true,
});

ftp.ls(".", function(err, res) {
  console.log('err is', err);
});

const person = fs.readFileSync('person.json');
ftp.put(person, 'person.json', function(hadError) {
  if (!hadError)
    console.log("File transferred successfully!");
});

person.json

{
  "name": "alex",
  "age": 24
}

It hangs after printing err is null. Let me know if I can do anything else.

alextes avatar Jun 08 '17 11:06 alextes

You probably need to read person as a buffer I think readFileSync defaults to utf8

devotox avatar Dec 18 '17 15:12 devotox

@devotox nope, the default for readFile encoding is null in which case it returns a buffer 😉 .

alextes avatar Dec 21 '17 09:12 alextes

When I read https://github.com/sergi/jsftp#ftpputsource-remotepath-callback I have impression that you could try

ftp.put('person.json', 'person.json', function(hadError) {
  if (!hadError)
    console.log("File transferred successfully!");
});

simonh1000 avatar Jan 14 '18 13:01 simonh1000

@simonh1000 true. This was a long time ago. I probably tried that too but can't be sure. In any case, the docs clearly state:

It accepts a string with the local path for the file, a Buffer, or a Readable stream as a source parameter.

alextes avatar Jan 14 '18 20:01 alextes