sergi / jsftp Goto Github PK
View Code? Open in Web Editor NEWLight and complete FTP client implementation for Node.js
License: MIT License
Light and complete FTP client implementation for Node.js
License: MIT License
when uploading files, either by buffer or local file path, I check the file on the server and see that it is empty and accessible as root (I log in with username/password credentials of a normal user).
After waiting for getting files it crashes with this message;
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT
at errnoException (net.js:901:11)
at Object.afterConnect as oncomplete
I'm trying to send multiple files to the ftp server and I'm usually losing connection after sending the first file. What's the best way to send more than one file to an ftp server.
I'm getting the files as base 64 strings through web sockets using socket.io and trying to send them using the put method.
Hello,
I am having trouble getting jsftp to do what i would like it to.
I am trying to code a script that copies a file or directory from one ftp connection to another ftp connection using a separate machine from either ftp connections.
any examples to get me started on streaming a file from one server to another would be very much appreciated.
When making two or more immediately (i.e. not waiting for callbacks) successive calls to .rename
, the server responds with a 503
. Use the code below to reproduce the error.
var Ftp = require('jsftp');
var client = new Ftp({
// config goes here
});
client.put('foo', new Buffer('bar'), function () {});
client.put('bar', new Buffer('foo'), function () {});
client.rename('foo', 'foobar', function () {});
client.rename('bar', 'barfoo', function (err) {console.dir(err)});
// { [Error: 503 Need RNFR before RNTO] code: 503 }
Looking at the implementation of .rename
, it looks to me like the RNTO
call isn't queued before the callback from the RNFR
call is received. Therefore it will be possible to smuggle other calls into the queue in between RNFR
and RNTO
, which probably is what causes the error.
Ideally .rename
should be changed in some way such that it produces only a single item to be queued.
I have a weird problem today. It seems I can't connect to my ftp. Maybe something broke when I updated my npm modules.
// Initialize some common variables
var user = "user ";
var pass = "pass";
var Ftp = require('jsftp');
var ftp = new Ftp({
host: "127.0.0.1",
port: 21, // The port defaults to 21, but let's include it anyway.
});
// First, we authenticate the user
ftp.auth(user, pass, function(err, res) {
if (err) throw err;
console.log("auth ok");
});
conn.auth opt.user, opt.pass, (err, res) ->
console.log conn.authorized # Returns true
console.log conn.features # Return undefined
Server is ftp://162.138.185.33/ (open government server for testing) and the login I'm using is Anonymous with an empty password. Is this just because I'm using an anonymous account or is this feature broken?
Im using ftp.ls(target_path, function (e, file_list) { console.warn(file_list); }) to get the information of a set fo files.
This is the output of one singel file i have in the ftp ..
[ { name: 'hola.txt',
type: 0,
time: 997386540000,
size: '7',
owner: 'username',
group: 'groupname',
userPermissions: { read: true, write: true, exec: false },
groupPermissions: { read: true, write: false, exec: false },
otherPermissions: { read: true, write: false, exec: false } } ]
The problem is that the file was created today.. If i use the time to create a new date it seams the file is exactly 10 years old...
ftp.ls(target_path, function (e, file_list) { console.warn(new Date(file_list.time)); });
Thu Aug 09 2001 16:49:00 GMT-0300 (ART)
The result is correct for old files tho... It seems to be failing with newer files only ...
ftp.list("/test", function(err, data) {
if (err)
console.error(err);
console.log(data.text);
});
gives undefined
i have 4 files in folder test
When I execute
var ftp = new Ftp({
host: "virbo.org",
user: "anonymous",
port: 21, // Defaults to 21
pass: ""
});
ftp.ls("/", function(err, files){
if (err) return console.error(err);
console.log(files); // Contains an array of file objects
});
The console shows
Unrecognized format:
arie
This appears to be a problem with parsing the directory named "bourdarie". In the listing, I see that it has found a directory named "bourd" and not "bourdarie":
{ name: 'bourd',
type: 1,
time: 1302926400000,
size: '4096',
owner: '0',
group: '0',
userPermissions: { read: true, write: true, exec: true },
groupPermissions: { read: true, write: false, exec: true },
otherPermissions: { read: true, write: false, exec: true } },
events.js:71
throw arguments[1]; // Unhandled 'error' event
^
Error: Did not receive service ready response
at Socket.FTP.connect (/home/weigel/git/urlwatch/node_modules/ftp/ftp.js:136:32)
at Socket.EventEmitter.emit (events.js:96:17)
at TCP.onread (net.js:392:31)
Line 136 of ftp.js is:
self.emit('error', throw new Error('Did not receive service ready response'));
When I try request a file from a client (web browser), I'm trying to get a list of available files. Everything works until such time when the user not requested any files a long time. If you try to run again after 6 hours ftp.ls, this method doesn't call callback function.
Code exemple:
function authTpFtpServer(callback) {
ftp.auth(user, pass, function(err, res) {
console.log("auth result", arguments);
callback && callback(err, res);
});
}
function checkFileOnFtp(fileName, callback) {
ftp.ls("./", function(err, data) {
console.log("fpt.ls got list");
if (err) {
var code = err && err.code;
if (code == 530) { //auth error
console.log(code, "Error auth, reconnect to ftp server");
return authTpFtpServer(function() {
checkFileOnFtp(fileName, callback);
});
}
return callback && callback({
error: err
});
}
for (var i = 0, l = data.length; i < l; ++i) {
var item = data[i];
var name = item.name;
if (name == fileName) {
return callback && callback(null, true);
}
}
return callback && callback(null, false);
});
}
console.log("fpt.ls got list");
- don't run.
ftp.keepAlive - does not keep the server connection active long time
Hello,
i've go a script that connect to a ftp server with the jsftp lib and get a directory listening.
the output shows that:
220 "Welcome to ******** FTP service."
211-Features:
EPRT
EPSV
MDTM
PASV
REST STREAM
SIZE
TVFS
UTF8
211 End
user ************* some user ***********
331 Please specify the password.
pass *********
230 Login successful.
syst
215 UNIX Type: L8
type I
200 Switching to Binary mode.
Authentication Successful
stat ./input
550 Permission denied.
err: Error: 550 Permission denied.
the first problem is, on which statement I become the 550 error?
and than i connected over a shell with the ftp server and send the same commands to that (incl. directory listening), but i didn't become any error!
Error creating new remote folder /cca.mbaobao.com/static/p/gruntStudy/1.0.1 --> Error: 550 Can't create directory: N
o such file or directory
"gruntStudy" and "1.0.1" folder does not exist in remote.
when I created "gruntStudy" folder used cuteFTP, the command can run and "1.0.1" is created correctly
why?
Am I not understanding something?
Just seems as if it should do this to make the API more friendly... and less repetitive to use :-
I'm liking it so far though!
I've stripped down an issue I'm having to the following:
var paths = ['work/test/foo.html','work/test/main.css'];
ftp.auth(USER, PWD, function(err, data) {
for (var i=0; i < 2; i++) {
var remotePath = paths[i];
console.log(remotePath);
ftp.ls(remotePath, function showFile(err, res) {
if (err) return console.log(err);
console.log('found:'+res[0].name + ' ' + res[0].size);
});
}
});
Both of the files listed in the paths array exist on the remote server. However, when I run this, I get:
work/test/foo.html
work/test/main.css
found:work/test/foo.html 31
found:work/test/foo.html 31
So I get foo.html
produced twice on the showFile()
callback.
How to use active, not passive mode?
v0.2.0 just hangs and never gets the callback. 0.1.1 works fine
After the file has been successfully transferred, using:
ftp.raw.quit(function(err, data) {
if (err) return w.error(err);
});
to close the ftp connection, sometimes got an error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:130:12)
at ResponseParser.Writable.write (_stream_writable.js:178:5)
at write (_stream_readable.js:583:24)
at flow (_stream_readable.js:592:7)
at Socket.pipeOnReadable (_stream_readable.js:624:5)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
And sometimes it's okay. This might be a bug, I guess.
I am getting repeated "Error: Write EPIPE" errors when using jsftp (for repeated get operations, for what it's worth). The only function call from jsftp.js that I can see in the stack trace is:
Ftp.prototype.reemit = function(event) {
var self = this;
return function(data) { self.emit(event, data); }
};
There, at line 82 (version 1.2.1).
JSFPT send empty content over put to a file...
I have a FTP server that only runs with TLS. So an encryption si required explicit FTP over TLS in order to connect to the server.
How could we implement this in node?
had try:
var Ftp = require('jsftp');
Ftp.useList = false
var ftp = new Ftp({
host: "192.168.1.101",
port: 21, // The port defaults to 21, but let's include it anyway.
});
ftp.useList = false
why not use it as a cfg/option?
It seems jsftp can't list files if the server doesn't supports the 'STAT' command.
While trying to do a "ftp.ls" I got :
$ node app.js
FTP socket connected
feat
500 'FEAT': command not understood.
user xp775
331 Password required for xp775.
PASS ****
230 User xp775 logged in.
stat /
502 STAT command not implemented.
/home/me/node-ftp/app.js:25
if (err) throw err;
^
502 STAT command not implemented.
$
For whatever reason I can't determine I am getting a socket error frequently when I try to initially get a file. If i just keep firing the script off eventually it works fine (downloads all the files I requested). The connection is happening and the file gets created (loacally) but, it doesn't download it.
node_modules/jsftp/lib/jsftp.js:422
socket.on('readable', function() {
^
TypeError: Cannot call method 'on' of undefined
I'm trying to ls a directory with 1500 files in it. After about 40 files, it appears that an extra newline character end up in 'entries', and then the entry parser splits the entries in the middle of the line. That results in messages like this:
Unrecognized format: n_Product_Catalog.txt.gz
If I try to FTP.put() a buffer to a filepath whose parent directory doesn't exist on the FTP server, no error is passed to the callback function. For example, if I have an empty /public_html directory on the server, and try to put() a file to /public_html/non-existent-directory/file.ext, the file doesn't get uploaded (obviously), but both the error and response parameters that get passed to the callback function are undefined.
Data outputs [] when I try to get a listing from a Proftpd server.
Here's the data I got:
stat /test
211-Status of /test:
211-drwxr-x--- 2 user group 4096 Aug 22 03:45 .
211-drwxr-x--- 5 user group 4096 Aug 22 03:45 ..
211--rw-r----- 1 user group 0 Aug 22 03:45 test1
211--rw-r----- 1 user group 0 Aug 22 03:45 test2
211--rw-r----- 1 user group 0 Aug 22 03:45 test3
211 End of status
It appears that this library doesn't expose a way to forcefully close the FTP connection. Am I missing something obvious?
Hello again,
I have a "TypeError: Cannot call method 'on' of undefined" error that is thrown at line 403:
socket.on('readable', function() {
self.emitProgress({
filename: remotePath,
action: 'get',
socket: this
});
});
Perhaps checking that we receive a socket before use would be helpful here? If it helps, the only two operations I'm doing over ftp are ls and get (writing an FTP synchronizer that pulls files from a remote directory).
I am trying to implement a simple case where I check for the existence of a remote folder (FileZilla Server version 0.9.30) via ftp.ls
- if it exists no action is performed but if it doesn't I try and create it with ftp.raw.mkd
:
ftp.ls(el, function(err, res) {
if (err) {
console.log("Remote folder not found: " + el);
ftp.raw.mkd(el, function(err, res) {
if (err) {
console.log("Error creating new remote folder " + el + " --> " + err);
} else {
console.log("New remote folder created " + el);
}
});
} else {
console.log("Remote folder found: " + el);
}
});
The problem I am experiencing is that sometimes the socket gets closed before the response from the FTP server is received. Given that it is an intermittent issue I am not sure what is causing it.
The way I tried to diagnose this issue is by defining a listener for the close
event in the ftpPasv
module. While monitoring the log on the server I could see that the issue happens always when the server is sending back 550 Directory not found
but the socket gets closed before this response is received.
I think that in addition to the data
, end
and error
events, the close
event should also be handled and try to address scenarios such as the one I am describing.
var JSFtp = require("jsftp");
var Ftp = new JSFtp({
host: "192.168.1.85",
port: 21, // defaults to 21
user: "root", // defaults to "anonymous"
pass: "root" // defaults to "@anonymous"
});
Ftp.list('/a/b', function(err, res) {
res.forEach(function(file) {
console.log(file.name);
});
TypeError: Object drw-rw-rw- 1 user group 0 Nov 28 13:47 .
drw-rw-rw- 1 user group 0 Nov 28 13:47 ..
-rw-rw-rw- 1 user group 9 Nov 28 13:45 file.txt
has no method 'forEach'
at eval (file:///D:/workspace/hzm/hzm_file_client/ftp.html:25:9)
at eval (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\lib\jsftp.js:344:7)
at f (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\node_modules\once\once.js:16:25)
at Array.eval (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\lib\jsftp.js:325:5)
at Ftp.parse (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\lib\jsftp.js:221:13)
at Ftp.parseResponse (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\lib\jsftp.js:136:8)
at Stream.eval (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\lib\jsftp.js:107:24)
at Stream.EventEmitter.emit (events.js:95:17)
at ResponseParser.reemit (D:\workspace\hzm\hzm_file_client\node_modules\jsftp\node_modules\event-stream\node_modules\stream-combiner\node_modules\duplexer\index.js:70:25)
at ResponseParser.EventEmitter.emit (events.js:95:17)
I am having a problem when I am trying to PUT a file to Akamai's FTP. When I run it from my Mac OSX, everything works as expected. When I run it from Ubuntu or Linux Mint, I receive a ECONNREFUSED. I even tried an Ubuntu instance in Amazon to make sure it wasn't something on my network.
I've tried everything and am out of options. Any ideas? Can I get you more information to help debug this issue?
Thank you in advanced.
Hi,
I encounter this error every time the ftp.auth() fails. When i entered wrong credentials (letters in host), the error "events.js 72 throw er;" comes out. The callback function cannot catch the error.
Then i tried catching the error by adding a listener, this is what i got.
{[Error: getaddrinffo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
I think, this can be fixed by adding validation in host.
I added some logging to investigate and it appears the responses from the server are not being properly parsed, resulting in "Error: PASV: Bad host/port combination"
ftp.auth
------
user REDACTED
331 Please specify the password.
pass REDACTED
230 Login successful.
type I
200 Switching to Binary mode.
ftp.list
------
type A
200 Switching to ASCII mode.
pasv
227 Entering Passive Mode (REDACTED,208,153).
type I
226 Directory send OK.
ftp.get
------
pasv
200 Switching to Binary mode.
There was an error retrieving the file.
Error: PASV: Bad host/port combination
/node_modules/jsftp/lib/jsftp.js:422
socket.on('readable', function() {
TypeError: Cannot call method 'on' of undefined
The commands and responses get out of sync after the second "type I" command and the second "pasv" command receives a response to the "type I" command that it can't parse.
The following code produces the error listed below ( running nodejs 0.4.12, [email protected] ) :
var jsftp = require( 'jsftp' );
var ftp = jsftp( { host: 'ftp.awesomeftp.org', port: 21 } );
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object # has no method '_createSocket'
at /home/qbit/Development/mirr/node_modules/jsftp/jsftp.js:116:23
at Object. (/home/qbit/Development/mirr/ftp_mirror.js:2:11)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at Array. (module.js:430:10)
at EventEmitter._tickCallback (node.js:126:26)
Line 354 never checks for an error and I think this should be the way:
var listing = "";
this.setType("A", function() {
self.getPasvSocket(function(err, socket) {
if(err)
{
cb(err);
}
else
{
socket.on("data", function(data) {
listing += data;
});
socket.on("close", function(err) {
cb(err || null, listing);
});
socket.on("error", cb);
self.send("list " + (path || ""));
}
});
});
How to use secure connection ?
With tcpdump I didn't see the second ftp connection that should be used, if I remember correctly, to get the file listing.
ftp.auth(user, pass, function(err, res) {
if (err) throw err;
ftp.ls("/", function(err, data) {
if (err) throw err;
console.log("data", data);
ftp.raw.quit(function(err, res) {
if (err) throw err;
console.log("FTP session finalized! See you soon!");
});
});
});
feat
220 FTP server (Hummingbird Ltd. (HCLFTPD) Version 7.0.0.0) ready.
500 'FEAT': command not understood.
user userName
331 Password required for userName.
pass password
230 User userName logged in.
stat /
502 STAT command not implemented.
type A
200 Type set to A.
pasv
227 Entering Passive Mode (10,1,10,11,10,217)
LIST /
150 Opening data connection for / (10.1.10.12,33571) (0 bytes).
quit
226 Transfer complete.
221 Goodbye.
$ node app.js
FTP socket connected
feat
500 'FEAT': command not understood.
user userName
331 Password required for userName.
PASS ****
230 User userName logged in.
stat /
502 STAT command not implemented.
type A
200 Type set to A.
pasv
227 Entering Passive Mode (10,1,10,11,10,217)
LIST /
150 Opening data connection for / (10.1.10.12,33571) (0 bytes).
data []
quit
221 Goodbye.
FTP session finalized! See you soon!
Ftp socket closed its doors to the public.
Hi there -
Shortly after issuing a raw quit on my FTP connection I an receiving an error complaining that err is not defined. See below:
jsftp/jsftp.js:176
!err && send();
^
ReferenceError: err is not defined
jsftp/jsftp.js:176:22
at Socket.<anonymous> (jsftp/jsftp.js:267:26)
at Socket.emit (events.js:88:20)
at Object.afterConnect [as oncomplete] (net.js:616:10)
Path names to the files have been shortened.
Here is my code: https://gist.github.com/1846894
Upload file takes (input file, output file name, res)...res being the response object for the node web server. At the end of the upload I'm sending a "upload complete" message to the user, right after quitting. However, shortly after disconnecting the session and notifying the user...an error takes down the whole application.
Is there a way to open existing file and append?
While uploading a file through "put", the object returned by "progress" event doesn't have "transferred" data.
Example:
this is always returned when i console.log progress data:
{ filename: '/test.zip',
action: 'put',
total: 268295573,
transferred: undefined }
NPM warning while installing:
npm WARN [email protected] package.json: bugs['web'] should probably be bugs['url']
npm: 1.1.0-3
node.js: 0.6.10
With a user supplied IP where there is no host at that IP, ftp.auth() takes a long time to throw ETIMEDOUT. Using the following code, on OS X I tested to a local IP with no device at that address. It took about 80 seconds to timeout. Shouldn't it be much less? I'm thinking 4-5 seconds (in terms of enduser patience until their mistake is evident).
var os = require("os"),
fs = require("fs"),
JSFtp = require("jsftp");
var HOST = '192.168.0.99';
var PORT;
var USER = 'tim';
var PWD = 'blah';
var ftp = new JSFtp({
host: HOST
});
// connect to remote
ftp.auth(USER, PWD, function (err, data) {
if (err) {
console.log('Failed to connect to remote: ' + err);
return;
}
// emit connect
console.log('Connected ' + data.text);
ftp.raw.quit(function (err, data) {
console.log('quit:' + data);
});
});
I just installed the latest as part of a package I'm working on. It's always worked fine before, but tonight I'm getting this error. I solved by npm install ftp-response-parser
. Probably just need to add that module to the jsftp package. See pull request #69 .
module.js:340
throw err;
^
Error: Cannot find module 'ftp-response-parser'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/[my-app-dir]/node_modules/jsftp/lib/jsftp.js:13:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I just updated jsftp to 0.1.0 and I got this error.
/home/bbigras/node-ftp/node_modules/jsftp/jsftp.js:507
.split(/\r\n|\n/)
^
TypeError: Cannot call method 'split' of undefined
at entriesToList (/home/bbigras/node-ftp/node_modules/jsftp/jsftp.js:507:22)
at /home/bbigras/node-ftp/node_modules/jsftp/jsftp.js:495:21
at Socket.<anonymous> (/home/bbigras/node-ftp/node_modules/jsftp/lib/ftpPasv.js:40:21)
at Socket.emit (events.js:61:17)
at Socket._onReadable (net.js:658:51)
at IOWatcher.onReadable [as callback] (net.js:177:10)
var localFile1 = new Array();
localFile1.push("d:/2/fff/1.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/1.txt");
localFile1.push("d:/2/fff/2.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/2.txt");
localFile1.push("d:/2/fff/3.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/3.txt");
localFile1.push("d:/2/fff/4.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/4.txt");
localFile1.push("d:/2/fff/5.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/5.txt");
localFile1.push("d:/2/fff/6.txt===/hzm/550E8400-E29B-11D4-A716-446655440000/6.txt");
function uploadOneFile(num){console.log(localFile1[num]);
Ftp1.put(localFile1[num].split("===")[0],localFile1[num].split("===")[1], function(hadError,socket) {
console.log(hadError);
num++;
if(num!=localFile1.length)uploadOneFile(num);
});
}
jsftp ignores the host portion of the PASV response text in getPasvSocket.
Instead it uses self.host which is the host originally connected to.
If the host IP returned by PASV is different from the host originally connected to, then an ECONNREFUSED is raised when establishing the connection, this is common is CDN's such as Akamai or Edgecast.
The fix is to make getPasvSocket to parse both host and port from the PASV command response text, for example -
if res.text is [a,b,c,d,e,f,g]
host is a.b.c.d
port is 256 * f + g
Cheers
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.