Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ftp_user.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations) (download) (as text)
Wed Feb 25 13:47:38 2009 UTC (15 years, 1 month ago) by hirohitohigashi
Original Path: trunk/ftp_auth.c
File MIME type: text/x-csrc
File size: 2995 byte(s)
Starting 2nd version of libOftp project. There are new designs.

1 /*
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 int ftp_auth( LIBOFTP *ftp, const char *user, const char *pass )
42 {
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 if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) {
51 DEBUGPRINT1( "auth: user command sending error.%s\n", "" );
52 return -1;
53 }
54
55 if( ftp_receive_response( ftp, 0, 0 ) == 230 ) { /* 230: User logged in, proceed. */
56 goto PROCEED;
57 }
58
59 /*
60 * send password.
61 */
62 snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass );
63 if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) {
64 DEBUGPRINT1( "auth: pass command sending error.%s\n", "" );
65 return -1;
66 }
67
68 if( ftp_receive_response( ftp, 0, 0 ) != 230 ) { /* 230: User logged in, proceed. */
69 DEBUGPRINT1( "auth: user authentication error.%s\n", "" );
70 return -2;
71 }
72
73 PROCEED:
74 /*
75 * system type.
76 */
77 snprintf( str1, sizeof(str1)-1, "SYST\r\n" );
78 if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) {
79 DEBUGPRINT1( "auth: syst command sending error.%s\n", "" );
80 return -1;
81 }
82
83 ret = ftp_receive_response( ftp, str1, sizeof(str1) );
84 if( ret == 215 ) {
85 if( strstr( str1, "UNIX" ) != 0 ) {
86 ftp->system_type = UNIX;
87 } else if( strstr( str1, "Windows_NT" ) != 0 ) {
88 ftp->system_type = Windows_NT;
89 }
90 DEBUGPRINT1( "auth: system type is %d\n", ftp->system_type );
91 }
92
93 return 0;
94 }
95
96

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