Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/ftp_user.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations) (download) (as text)
Sat Feb 28 01:15:41 2009 UTC (15 years ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 3118 byte(s)
functions renamed. ftp_connect() to ftp_open, ftp_auth() to ftp_user(). because ftp command compatible.

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     int ret;
45    
46     /*
47     * send user name.
48     */
49     snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user );
50 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
51 hirohitohigashi 25 DEBUGPRINT1( "user: user command sending error.%s\n", "" );
52 hirohitohigashi 17 return -1;
53     }
54    
55 hirohitohigashi 25 ret = ftp_receive_response( ftp, 0, 0 );
56     if( ret == 230 ) { /* 230: User logged in, proceed. */
57 hirohitohigashi 17 goto PROCEED;
58     }
59 hirohitohigashi 25 if( ret != 331 ) { /* 331: User name okay, need password. */
60     DEBUGPRINT1( "user: USER command response error. %d\n", ret );
61     return -1;
62     }
63 hirohitohigashi 17
64     /*
65     * send password.
66     */
67     snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass );
68 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
69 hirohitohigashi 25 DEBUGPRINT1( "user: pass command sending error.%s\n", "" );
70 hirohitohigashi 17 return -1;
71     }
72    
73     if( ftp_receive_response( ftp, 0, 0 ) != 230 ) { /* 230: User logged in, proceed. */
74 hirohitohigashi 25 DEBUGPRINT1( "user: user authentication error.%s\n", "" );
75 hirohitohigashi 17 return -2;
76     }
77    
78     PROCEED:
79     /*
80     * system type.
81     */
82     snprintf( str1, sizeof(str1)-1, "SYST\r\n" );
83 hirohitohigashi 20 if( ftp_send_command( ftp, str1 ) < 0 ) {
84 hirohitohigashi 25 DEBUGPRINT1( "user: SYST command sending error.%s\n", "" );
85 hirohitohigashi 17 return -1;
86     }
87    
88     ret = ftp_receive_response( ftp, str1, sizeof(str1) );
89     if( ret == 215 ) {
90     if( strstr( str1, "UNIX" ) != 0 ) {
91     ftp->system_type = UNIX;
92     } else if( strstr( str1, "Windows_NT" ) != 0 ) {
93     ftp->system_type = Windows_NT;
94     }
95 hirohitohigashi 25 DEBUGPRINT1( "user: system type is %d\n", ftp->system_type );
96 hirohitohigashi 17 }
97    
98     return 0;
99     }
100    
101    

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