Solved

Unix Networks question

Posted on 1997-09-23
9
200 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

733 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