Permalink
Browse files

fix an issue not sending the 150 message when doing a RETR

  • Loading branch information...
jfromaniello committed Apr 3, 2012
1 parent e9f7999 commit a6198784f00835d3087b79b19f28097dc0bed039
Showing with 57 additions and 4 deletions.
  1. +5 −4 ftpd.js
  2. +52 −0 specs/retr.specs.js
View
@@ -504,12 +504,13 @@ function createServer(host, sandbox) {
socket.totsize = 0;
socket.filename = filename;
}
- fs.open(socket.sandbox + socket.filename, process.O_RDONLY, 0666, function (err, fd) {
- dotrace("DATA file " + socket.filename + " opened");
+ fs.open(socket.sandbox + socket.filename, "r", function (err, fd) {
+ console.trace("DATA file " + socket.filename + " opened");
+ socket.write("150 Opening " + socket.mode.toUpperCase() + " mode data connection\r\n");
function readChunk() {
fs.read(fd, 4096, socket.totsize, socket.mode, function(err, chunk, bytes_read) {
if(err) {
- dotrace("Erro reading chunk");
+ console.trace("Erro reading chunk");
throw err;
return;
}
@@ -519,7 +520,7 @@ function createServer(host, sandbox) {
readChunk();
}
else {
- dotrace("DATA file " + socket.filename + " closed");
+ console.trace("DATA file " + socket.filename + " closed");
pasvconn.end();
socket.write("226 Closing data connection, sent " + socket.totsize + " bytes\r\n");
fs.close(fd);
View
@@ -0,0 +1,52 @@
+require('should');
+var ftpd = require('../ftpd'), Ftp = require("jsftp"), fs = require("fs");
+
+
+describe('RETR ftpd command', function(){
+ var ftp, server;
+
+ beforeEach(function(done){
+ server = ftpd.createServer("127.0.0.1", fs.realpathSync(__dirname + '/../fixture'));
+ server.on("client:connected", function(socket) {
+ var username;
+ socket.on("command:user", function(user, success, failure) {
+ if (user) {
+ username = user;
+ success();
+ } else failure();
+ });
+
+ socket.on("command:pass", function(pass, success, failure) {
+ if (pass) success(username);
+ else failure();
+ });
+ });
+ server.listen(2021);
+ ftp = new Ftp({
+ host: "127.0.0.1",
+ port: 2021
+ });
+ ftp.auth("jose", "esoj", function(err, res) {
+ done();
+ });
+ });
+
+ it("should send a 150 changing mode before sending the content", function(done){
+ var messages=[];
+ ftp.socket.on("data", function(d){
+ messages.push(d);
+ });
+ ftp.setPassive({
+ mode: "A",
+ cmd: "RETR " + "/data.txt",
+ pasvCallback: function(err, buffer){
+ messages[3].should.eql("150 Opening ASCII mode data connection\r\n");
+ done();
+ }
+ });
+ });
+
+ afterEach(function(){
+ server.close();
+ });
+});

0 comments on commit a619878

Please sign in to comment.