Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working on a program that involves uploading some files via FTP. However, I'd like to abort the process if the username and password given by the user are incorrect.

Is there any way to "test" if the pair is correct? Is a utility like ftp or curl able to do that, or should I use some feature (apparently hidden at my eyes) from libcurl?

Any ideas are really appreciated. Maybe this sound like a question coming from a dummy programmer, but indeed I've never dealt with FTP (or any other protocol) directly. Please consider writing "you didn't get the point" or "you're crazy" if needed.

share|improve this question
    
How are you planning to do the transfer? Using libcurl? What language are you programming in? –  cjm Jun 18 '11 at 0:52
    
@cjm, sorry, this should be included in the question. Yes, libcurl and C –  sidyll Jun 18 '11 at 1:05
    
I don't understand the question. You're writing an FTP client, right? Testing the user name and password are the server's job, it's called authentication. The first thing in an FTP session will be login and authentication. If that fails, the session aborts anyway. What were you expecting to do in your client? –  Gilles Jun 18 '11 at 9:00
    
@Gilles, thanks, and sorry. I know it's confusing (specially for me). To clarify, the program asks for the credentials in first hand, so I'd like to advice if something is wrong before doing the transfer. I though there was a specific method to do it, a "lightweight" one. @EightBitTtony got what I was trying to say. –  sidyll Jun 18 '11 at 14:39
add comment

1 Answer 1

up vote 2 down vote accepted

The short answer is - no you will need to try the FTP connection via libcurl and see if the authentication succeeds.

The username/password only exist on the remote server, and you don't know if they are being changed or altered at any stage (for legitimate reasons). Hence, your code will have to take credentials from the user, and basically try an FTP connection.

You could try an FTP operation which doesn't transfer data (i.e. just connect and then disconnect, or connect and do an ls then disconnect), which will allow libcurl to report an issue if authentication fails. Outside of that, no you can't realistically pre-authorise the credentials.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.