Unix Networks question

I wish to write a C program (ftp client) to copy files
from my ftp server. How do a set up a bare bones control connection and then a data connection for this? I also wish to receive a listing of the files to see what permissions they have and are they directories or files.
ranuAsked:
Who is Participating?
 
df020797Connect With a Mentor Commented:
The easiest way to achieve what you want is to set up a ordinary socket connection (AF_INET) and talk the ftp protocol. You also have to add a server on port 20 to handle incoming ftp data. FTP works with the client as client towards the server ona command channel on port 21 and data the other wy around onprot 20 (teh cleint becomes server and the server becomes client).
0
 
jlmsCommented:
I recommend you get a Linux distribution, or that you go to and ftp site that has one, this way you can get source code of a complete implementetion of an ftp client.

  Another idea is to get lynx (text web browser) source code, it has ftp client capabilities.
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
ranuAuthor Commented:
While your suggestion is a good pointer. I actually need a simple
program to implement the following;

1) The program takes in the following args;
    hostname[:portno] [local_directory [remote_directory]

2) program shd. ignore directories and shd. not recursively copy
   files. within a directory. It should created files on the
   client with permissions of S_IREAD and S_IWRITE. If a file
   is not accessible due to permissions just ignore it.

3) Program shd. terminate on error in control connection.

4) program shd. issue simple messages to stderr like "SUCCESS: n bytes copied". or "ERROR:write:no space left on device"


I guess a data connection will be required to transfer data retrieved from NLST and GET commands. This may be achieved as
below;

1.The client creates another socket with socket()
   2.The client binds an address to the socket with bind(). A port address of 0 is specified to obtain an ephemeral port.
   3.The client calls listen() to indicate willingness to accept a connection to the new socket.
   4.The client calls getsockname() to determine the port number of the socket.
   5.The client sends a PORT command to the server over the control connection to inform the server of the port number.
   6.The server connects to the new socket.
   7.The client sends the appropriate GET or NLST command over the control connection.
   8.The client calls accept() to accept the server's connection.

Culd you come up with a program that will simply do this for me?


0
 
n0thingCommented:
For 50 points ?? And it's not that simple if you ever took at
look at the ftpd & ftp client source code.
I think jlms is right. You should go get the source, read it &
use what you need. Besides, i don't know why you don't use rdist,
or rcp to do that.

0
 
ranuAuthor Commented:
Here, i increase the pts. to 100. Give me the code. This is for a simple implementation only, hence I
don't wish to make sophisticated system calls.
0
 
ranuAuthor Commented:
Here, i increase the pts. to 100. Give me the code. This is for a simple implementation only, hence I
don't wish to make sophisticated system calls.
0
 
ranuAuthor Commented:
Here, i increase the pts. to 100. Give me the code. This is for a simple implementation only, hence I
don't wish to make sophisticated system calls.
0
 
sjl100297Commented:
"Don't wish to make sophisticated system calls"? There's no way around it, if you want to do FTP, you have to know how the network code works. As has already been suggested, download an FTP client from a Linux archive.

If you still want to write it yourself, I would suggest you have a look at Stevens: Unix Network Programming, and Advanced Programming in the Unix Environment.

You obviously have very little idea of what is involved in something of this nature.

As somebody else has suggested, rdist or rcp might be what you need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.