| 38 |
*@note |
*@note |
| 39 |
* 認証後、定型的なコマンドも送信する。 |
* 認証後、定型的なコマンドも送信する。 |
| 40 |
*/ |
*/ |
| 41 |
int ftp_auth( 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 ret; |
| 47 |
* send user name. |
* send user name. |
| 48 |
*/ |
*/ |
| 49 |
snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user ); |
snprintf( str1, sizeof(str1)-1, "USER %s\r\n", user ); |
| 50 |
if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) { |
if( ftp_send_command( ftp, str1 ) < 0 ) { |
| 51 |
DEBUGPRINT1( "auth: user command sending error.%s\n", "" ); |
DEBUGPRINT1( "user: user command sending error.%s\n", "" ); |
| 52 |
return -1; |
return -1; |
| 53 |
} |
} |
| 54 |
|
|
| 55 |
if( ftp_receive_response( ftp, 0, 0 ) == 230 ) { /* 230: User logged in, proceed. */ |
ret = ftp_receive_response( ftp, 0, 0 ); |
| 56 |
|
if( ret == 230 ) { /* 230: User logged in, proceed. */ |
| 57 |
goto PROCEED; |
goto PROCEED; |
| 58 |
} |
} |
| 59 |
|
if( ret != 331 ) { /* 331: User name okay, need password. */ |
| 60 |
|
DEBUGPRINT1( "user: USER command response error. %d\n", ret ); |
| 61 |
|
return -1; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
/* |
/* |
| 65 |
* send password. |
* send password. |
| 66 |
*/ |
*/ |
| 67 |
snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass ); |
snprintf( str1, sizeof(str1)-1, "PASS %s\r\n", pass ); |
| 68 |
if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) { |
if( ftp_send_command( ftp, str1 ) < 0 ) { |
| 69 |
DEBUGPRINT1( "auth: pass command sending error.%s\n", "" ); |
DEBUGPRINT1( "user: pass command sending error.%s\n", "" ); |
| 70 |
return -1; |
return -1; |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
if( ftp_receive_response( ftp, 0, 0 ) != 230 ) { /* 230: User logged in, proceed. */ |
if( ftp_receive_response( ftp, 0, 0 ) != 230 ) { /* 230: User logged in, proceed. */ |
| 74 |
DEBUGPRINT1( "auth: user authentication error.%s\n", "" ); |
DEBUGPRINT1( "user: user authentication error.%s\n", "" ); |
| 75 |
return -2; |
return -2; |
| 76 |
} |
} |
| 77 |
|
|
| 80 |
* system type. |
* system type. |
| 81 |
*/ |
*/ |
| 82 |
snprintf( str1, sizeof(str1)-1, "SYST\r\n" ); |
snprintf( str1, sizeof(str1)-1, "SYST\r\n" ); |
| 83 |
if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) { |
if( ftp_send_command( ftp, str1 ) < 0 ) { |
| 84 |
DEBUGPRINT1( "auth: syst command sending error.%s\n", "" ); |
DEBUGPRINT1( "user: SYST command sending error.%s\n", "" ); |
| 85 |
return -1; |
return -1; |
| 86 |
} |
} |
| 87 |
|
|
| 92 |
} else if( strstr( str1, "Windows_NT" ) != 0 ) { |
} else if( strstr( str1, "Windows_NT" ) != 0 ) { |
| 93 |
ftp->system_type = Windows_NT; |
ftp->system_type = Windows_NT; |
| 94 |
} |
} |
| 95 |
DEBUGPRINT1( "auth: system type is %d\n", ftp->system_type ); |
DEBUGPRINT1( "user: system type is %d\n", ftp->system_type ); |
| 96 |
} |
} |
| 97 |
|
|
| 98 |
return 0; |
return 0; |