| 10 |
/***** Feature test switches ************************************************/ |
/***** Feature test switches ************************************************/ |
| 11 |
/***** System headers *******************************************************/ |
/***** System headers *******************************************************/ |
| 12 |
#include <unistd.h> |
#include <unistd.h> |
| 13 |
|
#include <string.h> |
| 14 |
#include <sys/types.h> |
#include <sys/types.h> |
| 15 |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
#include <string.h> |
|
|
#include <errno.h> |
|
| 16 |
|
|
| 17 |
|
|
| 18 |
/***** Local headers ********************************************************/ |
/***** Local headers ********************************************************/ |
| 31 |
/***** Global variables *****************************************************/ |
/***** Global variables *****************************************************/ |
| 32 |
/***** Signal catching functions ********************************************/ |
/***** Signal catching functions ********************************************/ |
| 33 |
/***** Local functions ******************************************************/ |
/***** Local functions ******************************************************/ |
|
/***** Global functions *****************************************************/ |
|
| 34 |
|
|
| 35 |
/****************************************************************************/ |
/****************************************************************************/ |
| 36 |
/*! バッファへファイル取得 |
/*! バッファへリスト取得 作業ルーチン |
| 37 |
* |
* |
| 38 |
*@param ftp LIBOFTPへのポインタ。 |
*@param ftp LIBOFTPへのポインタ。 |
| 39 |
*@param fname サーバ上のファイル名 |
*@param cmd コマンド (RETR|LIST|NLST) |
| 40 |
|
*@param fname ファイル名または、グロブ。 |
| 41 |
*@param buf バッファへのポインタ |
*@param buf バッファへのポインタ |
| 42 |
*@param bufsiz バッファサイズ |
*@param bufsiz バッファサイズ |
| 43 |
*@retval int 取得したバイト数 マイナス値ならエラーコード |
*@retval int 取得したバイト数 マイナス値ならエラーコード |
| 44 |
*@note |
*@note |
| 45 |
*/ |
*/ |
| 46 |
int ftp_get_buffer( LIBOFTP *ftp, const char *fname, char *buf, int bufsiz ) |
static int ftp_get_buffer_main( LIBOFTP *ftp, const char *cmd, const char *fname, char *buf, int bufsiz ) |
| 47 |
{ |
{ |
| 48 |
int data_socket; |
int data_socket; |
| 49 |
char *p = buf; |
char *p = buf; |
| 50 |
int res; |
int res; |
| 51 |
|
|
| 52 |
|
if( ftp->socket < 0 ) return LIBOFTP_ERROR; |
| 53 |
|
|
| 54 |
/* |
/* |
| 55 |
* 受信準備 |
* 受信準備 |
| 56 |
*/ |
*/ |
| 57 |
if( ftp->flag_passive ) { |
if( ftp->flag_passive ) { |
| 58 |
data_socket = ftp_getready_pasv( ftp, "RETR", fname ); |
data_socket = ftp_getready_pasv( ftp, cmd, fname ); |
| 59 |
} else { |
} else { |
| 60 |
data_socket = ftp_getready_active( ftp, "RETR", fname ); |
data_socket = ftp_getready_active( ftp, cmd, fname ); |
| 61 |
} |
} |
| 62 |
if( data_socket < 0 ) { |
if( data_socket < 0 ) { |
| 63 |
return data_socket; |
return data_socket; |
| 137 |
return LIBOFTP_ERROR_BUFFER; |
return LIBOFTP_ERROR_BUFFER; |
| 138 |
} |
} |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
/***** Global functions *****************************************************/ |
| 144 |
|
|
| 145 |
|
/****************************************************************************/ |
| 146 |
|
/*! バッファへファイル取得 |
| 147 |
|
* |
| 148 |
|
*@param ftp LIBOFTPへのポインタ。 |
| 149 |
|
*@param fname サーバ上のファイル名 |
| 150 |
|
*@param buf バッファへのポインタ |
| 151 |
|
*@param bufsiz バッファサイズ |
| 152 |
|
*@retval int 取得したバイト数 マイナス値ならエラーコード |
| 153 |
|
*@note |
| 154 |
|
*/ |
| 155 |
|
int ftp_get_buffer( LIBOFTP *ftp, const char *fname, char *buf, int bufsiz ) |
| 156 |
|
{ |
| 157 |
|
return ftp_get_buffer_main( ftp, "RETR", fname, buf, bufsiz ); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
/****************************************************************************/ |
| 163 |
|
/*! ディレクトリリスト(LIST) 取得 |
| 164 |
|
* |
| 165 |
|
*@param ftp LIBOFTPへのポインタ。 |
| 166 |
|
*@param fglob ファイルリストグロブ (ex: *.txt) or NULL |
| 167 |
|
*@param buf バッファへのポインタ |
| 168 |
|
*@param bufsiz バッファサイズ |
| 169 |
|
*@retval int エラーコード |
| 170 |
|
*@note |
| 171 |
|
*/ |
| 172 |
|
int ftp_list( LIBOFTP *ftp, const char *fglob, char *buf, int bufsiz ) |
| 173 |
|
{ |
| 174 |
|
int ret; |
| 175 |
|
|
| 176 |
|
ret = ftp_get_buffer_main( ftp, "LIST", fglob, buf, bufsiz ); |
| 177 |
|
if( ret > 0 ) { |
| 178 |
|
buf[ret] = 0; |
| 179 |
|
return LIBOFTP_NOERROR; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
return ret; |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
/****************************************************************************/ |
| 188 |
|
/*! ディレクトリリスト(NLST) 取得 |
| 189 |
|
* |
| 190 |
|
*@param ftp LIBOFTPへのポインタ。 |
| 191 |
|
*@param fglob ファイルリストグロブ (ex: *.txt) or NULL |
| 192 |
|
*@param buf バッファへのポインタ |
| 193 |
|
*@param bufsiz バッファサイズ |
| 194 |
|
*@retval int エラーコード |
| 195 |
|
*@note |
| 196 |
|
*/ |
| 197 |
|
int ftp_nlist( LIBOFTP *ftp, const char *fglob, char *buf, int bufsiz ) |
| 198 |
|
{ |
| 199 |
|
int ret; |
| 200 |
|
|
| 201 |
|
ret = ftp_get_buffer_main( ftp, "NLST", fglob, buf, bufsiz ); |
| 202 |
|
if( ret > 0 ) { |
| 203 |
|
buf[ret] = 0; |
| 204 |
|
return LIBOFTP_NOERROR; |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
return ret; |
| 208 |
|
} |