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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
df020797Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Networking

From novice to tech pro — start learning today.