Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/ftp_user.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by hirohitohigashi, Sat Feb 28 01:15:41 2009 UTC revision 50 by hirohitohigashi, Wed Dec 2 15:13:30 2009 UTC
# Line 41  Line 41 
41  int ftp_user( LIBOFTP *ftp, const char *user, const char *pass )  int ftp_user( LIBOFTP *ftp, const char *user, const char *pass )
42  {  {
43      char str1[256];      char str1[256];
44      int ret;      int res;
45    
46        if( ftp->socket < 0 ) return LIBOFTP_ERROR;
47    
48      /*      /*
49       * send user name.       * send user name.
50       */       */
51      snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user );      snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user );
52      if( ftp_send_command( ftp, str1 ) < 0 ) {      if( ftp_send_command( ftp, str1 ) < 0 ) {
53          DEBUGPRINT1( "user: user command sending error.%s\n", "" );          DEBUGPRINT1( "user command sending error.%s\n", "" );
54          return -1;          return LIBOFTP_ERROR_OS;
55      }      }
56    
57      ret = ftp_receive_response( ftp, 0, 0 );      res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message) );
58      if( ret == 230 ) {                                          /* 230: User logged in, proceed. */      if( res == 230 ) {                                          /* 230: User logged in, proceed. */
59          goto PROCEED;          goto PROCEED;
60      }      }
61      if( ret != 331 ) {                                          /* 331: User name okay, need password. */      if( res != 331 ) {                                          /* 331: User name okay, need password. */
62          DEBUGPRINT1( "user: USER command response error. %d\n", ret );          DEBUGPRINT1( "USER command response error. %d\n", res );
63          return -1;          return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
64      }      }
65    
66      /*      /*
# Line 66  int ftp_user( LIBOFTP *ftp, const char * Line 68  int ftp_user( LIBOFTP *ftp, const char *
68       */       */
69      snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass );      snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass );
70      if( ftp_send_command( ftp, str1 ) < 0 ) {      if( ftp_send_command( ftp, str1 ) < 0 ) {
71          DEBUGPRINT1( "user: pass command sending error.%s\n", "" );          DEBUGPRINT1( "pass command sending error.%s\n", "" );
72          return -1;          return LIBOFTP_ERROR_OS;
73      }      }
74            
75      if( ftp_receive_response( ftp, 0, 0 ) != 230 ) {            /* 230: User logged in, proceed. */      res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message) );
76          DEBUGPRINT1( "user: user authentication error.%s\n", "" );      if( res != 230 ) {                                          /* 230: User logged in, proceed. */
77          return -2;          DEBUGPRINT1( "user authentication error.%s\n", "" );
78            return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
79      }      }
80    
81  PROCEED:  PROCEED:
# Line 81  PROCEED: Line 84  PROCEED:
84       */       */
85      snprintf( str1, sizeof(str1)-1, "SYST\r\n" );      snprintf( str1, sizeof(str1)-1, "SYST\r\n" );
86      if( ftp_send_command( ftp, str1 ) < 0 ) {      if( ftp_send_command( ftp, str1 ) < 0 ) {
87          DEBUGPRINT1( "user: SYST command sending error.%s\n", "" );          DEBUGPRINT1( "SYST command sending error.%s\n", "" );
88          return -1;          return LIBOFTP_ERROR_OS;
89      }      }
90    
91      ret = ftp_receive_response( ftp, str1, sizeof(str1) );      res = ftp_receive_response( ftp, str1, sizeof(str1) );
92      if( ret == 215 ) {      if( res == 215 ) {
93          if( strstr( str1, "UNIX" ) != 0 ) {          if( strstr( str1, "UNIX" ) != 0 ) {
94              ftp->system_type = UNIX;              ftp->system_type = UNIX;
95          } else if( strstr( str1, "Windows_NT" ) != 0 ) {          } else if( strstr( str1, "Windows_NT" ) != 0 ) {
96              ftp->system_type = Windows_NT;              ftp->system_type = Windows_NT;
97          }          }
98          DEBUGPRINT1( "user: system type is %d\n", ftp->system_type );          DEBUGPRINT1( "system type is %d\n", ftp->system_type );
99      }      }
100    
101      return 0;      return LIBOFTP_NOERROR;
102  }  }
       
   

Legend:
Removed from v.25  
changed lines
  Added in v.50

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