[medusa] Usage for recv_channel in ftp_server.py

Sam Rushing rushing@n...
Wed, 16 Feb 2000 01:15:28 -0800 (PST)


Youngbong Choe writes:
> hi, i'm a newbie in python and medusa.
> 
> I built a simple file server using asyncore.py and asynchat.py,
> recv_channel and xmit_channel classes.
> but i could not understatand recv_channel, xmit_channel flow exactly.

Unless you really *need* to use the FTP protocol, I would not
recommend modeling a new protocol on it (especially if your purpose is 
to learn how to do protocols!). It's a bit over-complicated
because of the way it uses separate data and command channels.

A simpler approach would be something modeled on HTTP, where
commands and data are sent over a single socket. [this works because
a TCP stream is a two-way communications channel; commands can go
in one direction, data the other]

> My question is this:
> 
> 1. After adding new xmit channel and then push_with_producer(....),
> how can a client get the data? need new socket? or using current socket?
> 2. After adding new recv channel, how can a client send the data?

This is what makes the ftp model complicated: since it uses a separate 
channel for data it is necessary to

1) set up a new listening socket
2) tell the client side what port to connect to
3) accept the client's connection, thereby
4) creating *another* socket, which you then send
the data over.

[I just described PASV-mode ftp, normal-mode FTP is just the
same only the client does the listening]

See? Very complicated compared to:

class simple_file_transfer_channel:
def __init__ (self, conn):
self.set_terminator ('\r\n')

[...]
def found_terminator (self):
self.buffer, filename = '', self.buffer
self.push_with_producer (hypothetical_filename_producer (filename))

[...]

In the above, you could request a file like this:

$ telnet mymachine 9021
/etc/resolv.conf<return>
[... contents of /etc/resolv.conf ...]

Hope that helps!

-Sam