Re: ftp LIST in C

From: Dragan Cvetkovic (d1r2a3g4a5n.NOSPAM@SPAM.t6h7t.net)
Date: 04/24/03


From: Dragan Cvetkovic <d1r2a3g4a5n.NOSPAM@SPAM.t6h7t.net>
Date: 24 Apr 2003 14:40:28 -0400


"zhisol" <zhisol@o2.pl> writes:

> I've stated writing simple application for linux that list directory of
> ftp server. I plan list subdirectories, too. But now, i have a PROBLEM.
> I use sockets.
>
> Connecting is simple, after assigni used only:
> sd=socket(...) //sd-socket descriptor
> connect(sd,...)
> for USER, PASS, TYPE A, PASV, PWD i used:
> send(sd,"USER\r\n",...)
> recv(sd,...)
> [...]
>
> and everything was OK, but with LIST... here i have BIG problem.
> How can i receive data from ftp? Loop with recv() do nothing :(
>
> I suppose that list return data and require new port open on client, but
> i don't know how can i know which port number? For connection to ftp i
> open port 21 and that's ok, but what know, I jammed :(.

You need to read RFC 959 (ftp://ftp.rfc-editor.org/in-notes/rfc959.txt):

      control connection

         The communication path between the USER-PI and SERVER-PI for
         the exchange of commands and replies. This connection follows
         the Telnet Protocol.

      data connection

         A full duplex connection over which data is transferred, in a
         specified mode and type. The data transferred may be a part of
         a file, an entire file or a number of files. The path may be
         between a server-DTP and a user-DTP, or between two
         server-DTPs.

On most UNIX systems control connection uses port 21 (ftp) and data uses
port 20 (ftp-data).

HTH, Dragan

-- 
Dragan Cvetkovic, 
To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer


Relevant Pages

  • Re: Iptables FTP question
    ... think all other related would be from specific modules,the FTP and IRC ... Keep in mind that connection ... source port of 20 if it is for port mode data connections(for a standard ... I would also break down your rules into chains instead of appending such ...
    (comp.security.firewalls)
  • Re: Passive means what during FTP?
    ... :227 Entering Passive Mode ... :ftp: connect: No route to host ... The FTP data transfer uses a connection that is separate from the ... address and port number to connect to for the data transfer. ...
    (comp.os.linux.setup)
  • RE: Telnet/ftp problems SBS2000
    ... Please make sure your client computers are configured as both Firewall ... will find two options "Enable folder view for FTP sites" and "Use Passive ... that the control connection has been successfully established, ... (other than port 21) ...
    (microsoft.public.windows.server.sbs)
  • Re: IPSwitch, Inc. WS_FTP Server
    ... > bounce attack as well as PASV connection hijacking. ... > The FTP bounce vulnerability allows a remote attacker to cause the ... > anonymously along with any internal addresses that the FTP server has ... That means it's got to handle a PORT ...
    (Bugtraq)
  • Re: FTP question
    ... |> I have one server that has had connectivity issues this past week ... |> directed at trying yet another ftp software. ... |> or an error about the socket connection. ... |> own modem and a Linksey router using Xp 64bit system. ...
    (microsoft.public.windowsxp.network_web)