| 1 |
hirohitohigashi |
18 |
/* |
| 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 |
hirohitohigashi |
32 |
#include <unistd.h> |
| 13 |
hirohitohigashi |
18 |
|
| 14 |
|
|
|
| 15 |
|
|
/***** Local headers ********************************************************/ |
| 16 |
|
|
#include "liboftp.h" |
| 17 |
|
|
#include "sub.h" |
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
/***** Constat values *******************************************************/ |
| 21 |
|
|
/***** Macros ***************************************************************/ |
| 22 |
|
|
/***** Typedefs *************************************************************/ |
| 23 |
|
|
/***** Function prototypes **************************************************/ |
| 24 |
|
|
/***** Local variables ******************************************************/ |
| 25 |
|
|
/***** Global variables *****************************************************/ |
| 26 |
|
|
/***** Signal catching functions ********************************************/ |
| 27 |
|
|
/***** Local functions ******************************************************/ |
| 28 |
|
|
/***** Global functions *****************************************************/ |
| 29 |
|
|
|
| 30 |
|
|
/****************************************************************************/ |
| 31 |
|
|
/*! QUIT������������ |
| 32 |
|
|
* |
| 33 |
|
|
*@param ftp LIBOFTP��������������������� |
| 34 |
hirohitohigashi |
30 |
*@retval int ������������������ |
| 35 |
hirohitohigashi |
18 |
*@note |
| 36 |
|
|
*/ |
| 37 |
|
|
int ftp_quit( LIBOFTP *ftp ) |
| 38 |
|
|
{ |
| 39 |
|
|
char str1[] = "QUIT\r\n"; |
| 40 |
hirohitohigashi |
29 |
int res; |
| 41 |
hirohitohigashi |
18 |
|
| 42 |
hirohitohigashi |
50 |
if( ftp->socket < 0 ) return LIBOFTP_ERROR; |
| 43 |
|
|
|
| 44 |
hirohitohigashi |
18 |
/* |
| 45 |
|
|
* send QUIT command |
| 46 |
|
|
*/ |
| 47 |
hirohitohigashi |
20 |
if( ftp_send_command( ftp, str1 ) < 0 ) { |
| 48 |
hirohitohigashi |
29 |
DEBUGPRINT1( "command sending error. %s\n", str1 ); |
| 49 |
hirohitohigashi |
46 |
res = LIBOFTP_ERROR_OS; |
| 50 |
|
|
goto CLOSE; |
| 51 |
hirohitohigashi |
18 |
} |
| 52 |
|
|
|
| 53 |
hirohitohigashi |
29 |
res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message)-1 ); |
| 54 |
hirohitohigashi |
32 |
if( res == 221 ) { /* 221: Service closing control connection. */ |
| 55 |
|
|
res = LIBOFTP_NOERROR; |
| 56 |
|
|
} else { |
| 57 |
hirohitohigashi |
29 |
DEBUGPRINT1( "command response error. %d\n", res ); |
| 58 |
hirohitohigashi |
32 |
if( res >= 0 ) res = LIBOFTP_ERROR_PROTOCOL; |
| 59 |
hirohitohigashi |
18 |
} |
| 60 |
|
|
|
| 61 |
hirohitohigashi |
32 |
/* |
| 62 |
|
|
* close socket. |
| 63 |
|
|
*/ |
| 64 |
hirohitohigashi |
46 |
CLOSE: |
| 65 |
hirohitohigashi |
32 |
close( ftp->socket ); |
| 66 |
hirohitohigashi |
50 |
ftp->socket = -1; |
| 67 |
hirohitohigashi |
32 |
|
| 68 |
|
|
return res; |
| 69 |
hirohitohigashi |
18 |
} |