Solved

Unix Networks question

Posted on 1997-09-23
9
195 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Join & Write a Comment

What is IRC? IRC (Internet Relay Chat) is a form of communication between multiple users. It is available freely to anyone with inernet access. IRC is a great way to communicate with others e.g. There is an IRC channel for Ubuntu Linux, which is fo…
#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now