• C

simple FTP client

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?

zahmadianAsked:
Who is Participating?
 
NopiusConnect With a Mentor Commented:
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
 
NopiusCommented:
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
 
vashukumarCommented:
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
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

 
zahmadianAuthor Commented:
why \r\n??
0
 
zahmadianAuthor Commented:
and how can I check to see if my access to the FTP server was approved?

I am using sockets in this program
0
 
NopiusCommented:
\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
 
zahmadianAuthor Commented:
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
 
zahmadianAuthor Commented:
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
 
NopiusCommented:
you should terminate each command with "\r\n", "QUIT" is not an exception.
0
 
zahmadianAuthor Commented:
but adding \r\n to the end of each string results in a compile error
0
 
NopiusCommented:
I mean ""QUIT\r\n"
0
 
NopiusCommented:
oops, that's correct: "QUIT\r\n"

0
 
zahmadianAuthor Commented:
thanks Nopius

I will try that
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.