Re: ftp LIST in C

From: Adie (a_usenetizen@hotmail.com)
Date: 04/25/03


From: Adie <a_usenetizen@hotmail.com>
Date: Fri, 25 Apr 2003 00:49:26 +0100


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

>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 :(.
>
>Could You help me?
>
>#cut of my code:
> [...]
> send(sd,"LIST\r\n", strlen("LIST") + 2, 0);
> n = recv (sd, buf, sizeof (buf), 0); //sd-socket descriptor
> while (n > 0)
> {
> buf[n] = '\0';
> printf ("%s", buf);
> n = recv (sd, buf, sizeof (buf), 0);
> }
>
>PS:sorry for my english;)

There are two connections needed, port 21 for commands, port 20 for
data. Youre asking for data, "LIST" on port 21 returns *data* and
hence is sent to port 20.



Relevant Pages

  • Re: 500 "LPRT 6,16,0,0,0,0...,34,113,2,7,184 New Information
    ... Try change it to port 21 and test again. ... if ftp is not bind to default port. ... >>Cleared up an issue with our firewall and now, ... >>connecting to 192.xxx.xxx.xxx:4774 ...
    (microsoft.public.inetserver.iis.ftp)
  • Re: Extremely abnormal behaviour: ftp client does show a file list in a folder occasionally
    ... from the first log u see the port range is within the range. ... IIS FTP to take effects. ... connecting to xxx.xxx.xx.xx:5013 ...
    (microsoft.public.inetserver.iis.ftp)
  • Re: FTP Server on Win XP Pro
    ... >connecting to 192.168.1.104:1434 ... This looks like you're running into a problem with your NAT router. ... external IP and port - but only if they know that you are running FTP. ...
    (microsoft.public.inetserver.iis.security)
  • Re: Connecting to FTP server through Winroute
    ... > I am having problems connecting to an ftp server through my local ... > of this server and he has noted that he is behind a firewall but has ... > had no problem connecting to it from other sites except one. ... specified data port, thereby defeating PASV mode. ...
    (comp.security.firewalls)
  • Re: ftp LIST in C
    ... > ftp server. ... > Connecting is simple, after assigni used only: ... > i don't know how can i know which port number? ... On most UNIX systems control connection uses port 21 and data uses ...
    (comp.unix.programmer)