?
Solved

simple FTP client

Posted on 2006-05-23
13
Medium Priority
?
255 Views
Last Modified: 2010-04-15
Hi experts

I am writing a simple FTP client program , which have to:
1- connect to the FTP server
2- sends user name and password
4- show the files(not other sub directorie) in the directory (eithe the dorectory user inserts or current directory)
5- recieve all those files.

in this part I have successfully connected to the FTP server, and I am trying to send my user name and password to the ftp server, my question is , is there any object or struct of type FTP, with USER and PASS field, or I should send them buy string buffers?

my program is to perform an anonymous login. This means the user name is to be ftp and the password will be the login name of the current user, followed by '@' and the fully qualified name of the host the application is running on.


any Idea?

0
Comment
Question by:zahmadian
  • 6
  • 6
13 Comments
 
LVL 27

Expert Comment

by:Nopius
ID: 16748379
if you are writing simple program,  using sockets and don't like to use external libraries for FTP, then
yes, use strings
"USER ftp\r\n"
and
"PASS lala@mail.com\r\n"
for logging in to the server.

To get more FTP protocol details read http://www.faqs.org/rfcs/rfc959.html if you haven't done this already.
0
 

Expert Comment

by:vashukumar
ID: 16748389
you can use curl library. Its provides API for sending FTP and HTTP requests to any server.

Visit this link for more info. ITs a freeware. Just download it, compile and link it in your program. Exhaustive documentation is provided for reference.

http://curl.haxx.se/docs/manpage.html
0
 

Author Comment

by:zahmadian
ID: 16748492
why \r\n??
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:zahmadian
ID: 16748497
and how can I check to see if my access to the FTP server was approved?

I am using sockets in this program
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16748546
\r\n are special characters carridge return and line feed.

Read section "4.2.  FTP REPLIES" of http://www.faqs.org/rfcs/rfc959.html
to see what reply codes are success and what are failure.

From there:

"A reply is defined to contain the 3-digit code, followed by Space
      <SP>, followed by one line of text (where some maximum line length
      has been specified), and terminated by the Telnet end-of-line
      code."

So you need read socket after the command was sent, then to analyze reply string
0
 

Author Comment

by:zahmadian
ID: 16748607
so I should check my buffer for the 3 digit numebr and then check that numebr to see what does that numebr corresponds to? by the way from where I can check does numbers?
0
 
LVL 27

Accepted Solution

by:
Nopius earned 2000 total points
ID: 16748625
Yes. But read entire line to a buffer, before analysing.
If number starts with 2, authorization is successfull.
In C:
if (buf[0]=='2') {//it's ok };
0
 

Author Comment

by:zahmadian
ID: 16748747
oh awsome, thanx Nopius

I want to know why when I send "QUIT" to the server that nothing happens

p.s.  I tried added \r\n to the end of my strings and I get a compilation error saying that I overflowed the implicit constant conversion
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16748852
you should terminate each command with "\r\n", "QUIT" is not an exception.
0
 

Author Comment

by:zahmadian
ID: 16748961
but adding \r\n to the end of each string results in a compile error
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16748972
I mean ""QUIT\r\n"
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16748980
oops, that's correct: "QUIT\r\n"

0
 

Author Comment

by:zahmadian
ID: 16749110
thanks Nopius

I will try that
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

840 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