-----Original Message-----
From: gabriele renzi <surrender_it@
To: ruby-talk / ruby-lang.org
Sent: 30/10/02 21:38
Subject: Tiny Featureless FTP server somewhere?

Hi gurus, 

Inspired from the "tiny featureless http server " message, I wondered
if someone worked on a  minimal ftp server .

Actually, I'm interested in the way (s)he handled the PORT/PASV thing,
I mean:

Hi,
 i am not a guru, but yesterday i wanted to see how an ftp server works,
so i wrote the following messy ftp client code. maybe you can glean
something from it:

require 'socket'


def get_file(client_socket,filename)
  file_acceptor = TCPServer.new('127.0.0.1',5120)
  client_socket.puts("retr #{filename}\r\n")
  print client_socket.gets
  select([file_acceptor],nil,nil,40)
  s = file_acceptor.accept
  str = s.gets(nil)
  s.close
  file_acceptor.close
  print "received string size=#{str.length}\n"
  str
end

def get_server_list(client_socket)
  file_acceptor = TCPServer.new('127.0.0.1',5120)
  client_socket.puts("nlst\r\n")
  print client_socket.gets
  select([file_acceptor],nil,nil,40)
  s = file_acceptor.accept
  str = s.gets(nil)
  s.close
  file_acceptor.close
  print "received string size=#{str.length}\n"
  str
end

t = TCPSocket.new('localhost',21)
msg = nil
begin
  msg = t.gets
  print msg  
end while(msg !~ /^\d\d\d\s/)
t.puts("user bill\r\n")
print t.gets
t.puts("pass mypasswd\r\n")
print t.gets
t.puts('help')
begin
  msg = t.gets
  print msg  
end while(msg !~ /^\d\d\d\s/)
p get_server_list(t)
t.puts("quit\r\n")