Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/ftp_user.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (hide annotations) (download) (as text)
Wed Dec 2 15:13:30 2009 UTC (14 years, 3 months ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 3352 byte(s)
add error check
1 hirohitohigashi 17 /*
2     liboftp: this is an FTP library to simplify the work to a Developer
3     who want to work with FTP servers (RFC 959).
4    
5     Copyright (c) 2009 hirohito higashi. All rights reserved.
6     This file is distributed under BSD license.
7     */
8    
9    
10     /***** Feature test switches ************************************************/
11     /***** System headers *******************************************************/
12     #include <stdio.h>
13     #include <string.h>
14    
15    
16     /***** Local headers ********************************************************/
17     #include "liboftp.h"
18     #include "sub.h"
19    
20    
21     /***** Constat values *******************************************************/
22     /***** Macros ***************************************************************/
23     /***** Typedefs *************************************************************/
24     /***** Function prototypes **************************************************/
25     /***** Local variables ******************************************************/
26     /***** Global variables *****************************************************/
27     /***** Signal catching functions ********************************************/
28     /***** Local functions ******************************************************/
29     /***** Global functions *****************************************************/
30    
31     /****************************************************************************/
32     /*! ���������������
33     *
34     *@param ftp LIBOFTP���������������������
35     *@param user ������������
36     *@param pass ���������������
37     *@retval int ������������������
38     *@note
39     * ������������������������������������������������������
40     */
41 hirohitohigashi 25 int ftp_user( LIBOFTP *ftp, const char *user, const char *pass )
42 hirohitohigashi 17 {
43     char str1[256];
44 hirohitohigashi 29 int res;
45 hirohitohigashi 17
46 hirohitohigashi 50 if( ftp->socket < 0 ) return LIBOFTP_ERROR;
47    
48 hirohitohigashi 17 /*
49     * send user name.
50     */
51     snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user );
52 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
53 hirohitohigashi 29 DEBUGPRINT1( "user command sending error.%s\n", "" );
54     return LIBOFTP_ERROR_OS;
55 hirohitohigashi 17 }
56    
57 hirohitohigashi 29 res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message) );
58     if( res == 230 ) { /* 230: User logged in, proceed. */
59 hirohitohigashi 17 goto PROCEED;
60     }
61 hirohitohigashi 29 if( res != 331 ) { /* 331: User name okay, need password. */
62     DEBUGPRINT1( "USER command response error. %d\n", res );
63     return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
64 hirohitohigashi 25 }
65 hirohitohigashi 17
66     /*
67     * send password.
68     */
69     snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass );
70 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
71 hirohitohigashi 29 DEBUGPRINT1( "pass command sending error.%s\n", "" );
72     return LIBOFTP_ERROR_OS;
73 hirohitohigashi 17 }
74    
75 hirohitohigashi 29 res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message) );
76     if( res != 230 ) { /* 230: User logged in, proceed. */
77     DEBUGPRINT1( "user authentication error.%s\n", "" );
78     return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
79 hirohitohigashi 17 }
80    
81     PROCEED:
82     /*
83     * system type.
84     */
85     snprintf( str1, sizeof(str1)-1, "SYST\r\n" );
86 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
87 hirohitohigashi 29 DEBUGPRINT1( "SYST command sending error.%s\n", "" );
88     return LIBOFTP_ERROR_OS;
89 hirohitohigashi 17 }
90    
91 hirohitohigashi 29 res = ftp_receive_response( ftp, str1, sizeof(str1) );
92     if( res == 215 ) {
93 hirohitohigashi 17 if( strstr( str1, "UNIX" ) != 0 ) {
94     ftp->system_type = UNIX;
95     } else if( strstr( str1, "Windows_NT" ) != 0 ) {
96     ftp->system_type = Windows_NT;
97     }
98 hirohitohigashi 29 DEBUGPRINT1( "system type is %d\n", ftp->system_type );
99 hirohitohigashi 17 }
100    
101 hirohitohigashi 29 return LIBOFTP_NOERROR;
102 hirohitohigashi 17 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26