jsftp
jsftp copied to clipboard
Uploading files does not work
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 }
Are you able to make a test that fails with your use case?
Was hoping to get a way with not including one 😛. Here you go @sergi :
- set up Ubuntu Yakkety
- install
vsftpd - configure ftp writing to be allowed
- restart
vsftpd - 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.
You probably need to read person as a buffer I think readFileSync defaults to utf8
@devotox nope, the default for readFile encoding is null in which case it returns a buffer 😉 .
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 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.