sergi / jsftp

Light and complete FTP client implementation for Node.js
MIT License
809 stars 154 forks source link

Uploading files does not work #248

Open alextes opened 7 years ago

alextes commented 7 years ago

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 }
sergi commented 7 years ago

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

alextes commented 7 years ago

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`
```json
{
  "name": "alex",
  "age": 24
}

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

devotox commented 6 years ago

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

alextes commented 6 years ago

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

simonh1000 commented 6 years ago

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!");
});
alextes commented 6 years ago

@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.