       @end()
     
     "PASV": ()->
-      socket = @
-      socket.passive = true
-      socket.dtpServer = net.createServer()
-      dtpHost = socket.server.address().address
-      socket.dtpServer.dataQueue = null
-      
-      socket.dtpServer.on 'listening', ()->
-        dtpAddress = @address()
-        console.log "Data Transfer Proccess Server listening on #{dtpAddress.address}:#{dtpAddress.port}"
-        host  = dtpAddress.address.split(".").join(",")
-        port1 = parseInt(dtpAddress.port / 256, 10)
-        port2 = dtpAddress.port % 256
-        socket.reply 227, "Entering Extended Passive Mode (#{host},#{port1},#{port2})"
-      
-      socket.dtpServer.on "connection", (dtpSocket)->
-        console.log "DTP Connect from #{dtpSocket.remoteAddress}"
-        dtpSocket.setTimeout(0)
-        dtpSocket.setNoDelay()
-        dtpSocket.dataEncoding = "binary"
-        
-        dtpSocket.on "end", ()->
-            socket.dtpServer.close()
-            socket.reply 226
-        dtpSocket.on "close", ()->
-          console.log "DTP Socket closed"
-        dtpSocket.on "connect", ()->
-          console.log "DTP Socket connect"
-        dtpSocket.on 'data', (recData)->
-          console.log recData.toString().trim()
-        
-        dtpSocket.sender = ()->
-          console.log socket.dtpServer.dataQueue
-          if socket.dtpServer.dataQueue isnt null
-            console.log "Send"
-            clearInterval(dtpSocket.intervalId)
-            dtpSocket.end(socket.dtpServer.dataQueue)
-        
-        dtpSocket.intervalId = setInterval(dtpSocket.sender, 100)
-      
-      socket.dtpServer.on "close", ()->
-        console.log "Data Transfer Proccess Server closed"
-        socket.passive = false
-        
-      socket.dtpServer.listen(0, dtpHost)
+      @passive = true
+      @dtpServer = dtpServer.call @, @
+      @dtpServer.listen 0, @server.address().address
     
     "NOOP": ()->
       @reply 200

#
# # Baby FTP Deamon
#
net       = require "net"
fs        = require "fs"
exec      = require("child_process").exec

module.exports = class BabyFtpd
  # Static variables

        CWD     QUIT    PASV    NOOP    HELP
        Direct comments to root
        """
  
  dtpServer = (socket)->
    dtp = net.createServer()
    
    dtp.on 'listening', ()->
      dtpAddress = @address()
      console.log "Data Transfer Proccess Server listening on #{dtpAddress.address}:#{dtpAddress.port}"
      host  = dtpAddress.address.split(".").join(",")
      port1 = parseInt(dtpAddress.port / 256, 10)
      port2 = dtpAddress.port % 256
      socket.reply 227, "Entering Extended Passive Mode (#{host},#{port1},#{port2})"
    
    dtp.on "close", ()->
      console.log "Data Transfer Proccess Server closed"
      socket.passive = false
    
    dtp.on "connection", (dtpSocket)->
      @dtpSocket = dtpSocket
      console.log "DTP Connect from #{dtpSocket.remoteAddress}"
      dtpSocket.setTimeout(0)
      dtpSocket.setNoDelay()
      dtpSocket.dataEncoding = "binary"
      
      dtpSocket.on "end", ()->
          socket.dtpServer.close()
          socket.reply 226
      dtpSocket.on "close", ()->
        console.log "DTP Socket closed"
      dtpSocket.on "connect", ()->
        console.log "DTP Socket connect"
      dtpSocket.on 'data', (recData)->
        console.log recData.toString().trim()
      
      dtpSocket.sender = (dataQueue)->
        socket.reply 150
        console.log "DTP Send"
        dtpSocket.end(dataQueue)
    dtp


class BabyFtpd.FileSystem
