00001 #ifndef HEADER_CURL_FTP_H 00002 #define HEADER_CURL_FTP_H 00003 /*************************************************************************** 00004 * _ _ ____ _ 00005 * Project ___| | | | _ \| | 00006 * / __| | | | |_) | | 00007 * | (__| |_| | _ <| |___ 00008 * \___|\___/|_| \_\_____| 00009 * 00010 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. 00011 * 00012 * This software is licensed as described in the file COPYING, which 00013 * you should have received as part of this distribution. The terms 00014 * are also available at https://curl.haxx.se/docs/copyright.html. 00015 * 00016 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 00017 * copies of the Software, and permit persons to whom the Software is 00018 * furnished to do so, under the terms of the COPYING file. 00019 * 00020 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 00021 * KIND, either express or implied. 00022 * 00023 ***************************************************************************/ 00024 00025 #include "pingpong.h" 00026 00027 #ifndef CURL_DISABLE_FTP 00028 extern const struct Curl_handler Curl_handler_ftp; 00029 00030 #ifdef USE_SSL 00031 extern const struct Curl_handler Curl_handler_ftps; 00032 #endif 00033 00034 CURLcode Curl_ftpsend(struct connectdata *, const char *cmd); 00035 CURLcode Curl_GetFTPResponse(ssize_t *nread, struct connectdata *conn, 00036 int *ftpcode); 00037 #endif /* CURL_DISABLE_FTP */ 00038 00039 /**************************************************************************** 00040 * FTP unique setup 00041 ***************************************************************************/ 00042 typedef enum { 00043 FTP_STOP, /* do nothing state, stops the state machine */ 00044 FTP_WAIT220, /* waiting for the initial 220 response immediately after 00045 a connect */ 00046 FTP_AUTH, 00047 FTP_USER, 00048 FTP_PASS, 00049 FTP_ACCT, 00050 FTP_PBSZ, 00051 FTP_PROT, 00052 FTP_CCC, 00053 FTP_PWD, 00054 FTP_SYST, 00055 FTP_NAMEFMT, 00056 FTP_QUOTE, /* waiting for a response to a command sent in a quote list */ 00057 FTP_RETR_PREQUOTE, 00058 FTP_STOR_PREQUOTE, 00059 FTP_POSTQUOTE, 00060 FTP_CWD, /* change dir */ 00061 FTP_MKD, /* if the dir didn't exist */ 00062 FTP_MDTM, /* to figure out the datestamp */ 00063 FTP_TYPE, /* to set type when doing a head-like request */ 00064 FTP_LIST_TYPE, /* set type when about to do a dir list */ 00065 FTP_RETR_TYPE, /* set type when about to RETR a file */ 00066 FTP_STOR_TYPE, /* set type when about to STOR a file */ 00067 FTP_SIZE, /* get the remote file's size for head-like request */ 00068 FTP_RETR_SIZE, /* get the remote file's size for RETR */ 00069 FTP_STOR_SIZE, /* get the size for STOR */ 00070 FTP_REST, /* when used to check if the server supports it in head-like */ 00071 FTP_RETR_REST, /* when asking for "resume" in for RETR */ 00072 FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */ 00073 FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */ 00074 FTP_PASV, /* generic state for PASV and EPSV, check count1 */ 00075 FTP_LIST, /* generic state for LIST, NLST or a custom list command */ 00076 FTP_RETR, 00077 FTP_STOR, /* generic state for STOR and APPE */ 00078 FTP_QUIT, 00079 FTP_LAST /* never used */ 00080 } ftpstate; 00081 00082 struct ftp_parselist_data; /* defined later in ftplistparser.c */ 00083 00084 struct ftp_wc_tmpdata { 00085 struct ftp_parselist_data *parser; 00086 00087 struct { 00088 curl_write_callback write_function; 00089 FILE *file_descriptor; 00090 } backup; 00091 }; 00092 00093 typedef enum { 00094 FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */ 00095 FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */ 00096 FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the 00097 file */ 00098 } curl_ftpfile; 00099 00100 /* This FTP struct is used in the Curl_easy. All FTP data that is 00101 connection-oriented must be in FTP_conn to properly deal with the fact that 00102 perhaps the Curl_easy is changed between the times the connection is 00103 used. */ 00104 struct FTP { 00105 curl_off_t *bytecountp; 00106 char *user; /* user name string */ 00107 char *passwd; /* password string */ 00108 00109 /* transfer a file/body or not, done as a typedefed enum just to make 00110 debuggers display the full symbol and not just the numerical value */ 00111 curl_pp_transfer transfer; 00112 curl_off_t downloadsize; 00113 }; 00114 00115 00116 /* ftp_conn is used for struct connection-oriented data in the connectdata 00117 struct */ 00118 struct ftp_conn { 00119 struct pingpong pp; 00120 char *entrypath; /* the PWD reply when we logged on */ 00121 char **dirs; /* realloc()ed array for path components */ 00122 int dirdepth; /* number of entries used in the 'dirs' array */ 00123 int diralloc; /* number of entries allocated for the 'dirs' array */ 00124 char *file; /* decoded file */ 00125 bool dont_check; /* Set to TRUE to prevent the final (post-transfer) 00126 file size and 226/250 status check. It should still 00127 read the line, just ignore the result. */ 00128 bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do anything. If 00129 the connection has timed out or been closed, this 00130 should be FALSE when it gets to Curl_ftp_quit() */ 00131 bool cwddone; /* if it has been determined that the proper CWD combo 00132 already has been done */ 00133 bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent 00134 caching the current directory */ 00135 bool wait_data_conn; /* this is set TRUE if data connection is waited */ 00136 char *prevpath; /* conn->path from the previous transfer */ 00137 char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a 00138 and others (A/I or zero) */ 00139 int count1; /* general purpose counter for the state machine */ 00140 int count2; /* general purpose counter for the state machine */ 00141 int count3; /* general purpose counter for the state machine */ 00142 ftpstate state; /* always use ftp.c:state() to change state! */ 00143 ftpstate state_saved; /* transfer type saved to be reloaded after 00144 data connection is established */ 00145 curl_off_t retr_size_saved; /* Size of retrieved file saved */ 00146 char *server_os; /* The target server operating system. */ 00147 curl_off_t known_filesize; /* file size is different from -1, if wildcard 00148 LIST parsing was done and wc_statemach set 00149 it */ 00150 /* newhost is the (allocated) IP addr or host name to connect the data 00151 connection to */ 00152 char *newhost; /* this is the pair to connect the DATA... */ 00153 unsigned short newport; /* connection to */ 00154 00155 }; 00156 00157 #define DEFAULT_ACCEPT_TIMEOUT 60000 /* milliseconds == one minute */ 00158 00159 #endif /* HEADER_CURL_FTP_H */