Solved

Unix Networks question

Posted on 1997-09-23
9
198 Views
Last Modified: 2013-12-23
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.
0
Comment
Question by:ranu
9 Comments
 
LVL 4

Expert Comment

by:jlms
ID: 1582599
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
 
LVL 84

Expert Comment

by:ozo
ID: 1582600
0
 

Author Comment

by:ranu
ID: 1582601
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

Expert Comment

by:n0thing
ID: 1582602
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
 

Author Comment

by:ranu
ID: 1582603
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
 

Author Comment

by:ranu
ID: 1582604
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
 

Author Comment

by:ranu
ID: 1582605
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
 

Expert Comment

by:sjl100297
ID: 1582606
"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
 
LVL 2

Accepted Solution

by:
df020797 earned 100 total points
ID: 1582607
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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question