Outbound port on sockets
gnewsg at gmail.com
Thu Sep 14 14:58:07 CEST 2006
> Is it possible to specify which port to use as the outbound port on a
> connection? I have the IP address and port number for the computer I'm
> trying to connect to (not listening for), but it's expecting my
> connection on a certain port.
> Specifically, I'm trying to write an FTP host, and I'm trying to
> implement the PORT command. From everything I've read, the client
> supplies the IP address and port number for where I'm supposed to
> connect to send it data (like a LISTing), and it's expecting me to
> connect over port 20. If anyone is familiar with FTP and can tell me
> whether this is true or not, whether I really need to go out on port
> 20, I'd appreciate it, as well.
This isn't correct.
If you send a PORT command you're telling server to establish a
connection with you, not the contrary. In this case, even if you are an
FTP client, you temporary ACCEPT an outbound connection from the FTP
The right format of a FTP PORT command is:
...where x(s) represents your IP address in dotted form and (x * y) the
TCP port you bind.
For further informations you can check RFC959 or take a look at ftplib
in standard module library. Also in twisted you can find a lot of
useful code in the module protocols.ftp.
More information about the Python-list