15ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#ifndef HEADER_CURL_FTP_H 25ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#define HEADER_CURL_FTP_H 35ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen/*************************************************************************** 45ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * _ _ ____ _ 55ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * Project ___| | | | _ \| | 65ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * / __| | | | |_) | | 75ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * | (__| |_| | _ <| |___ 85ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * \___|\___/|_| \_\_____| 95ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * 10e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. 115ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * 125ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * This software is licensed as described in the file COPYING, which 135ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * you should have received as part of this distribution. The terms 14d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo * are also available at https://curl.haxx.se/docs/copyright.html. 155ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * 165ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * You may opt to use, copy, modify, merge, publish, distribute and/or sell 175ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * copies of the Software, and permit persons to whom the Software is 185ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * furnished to do so, under the terms of the COPYING file. 195ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * 205ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 215ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * KIND, either express or implied. 225ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * 235ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen ***************************************************************************/ 245ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 255ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#include "pingpong.h" 265ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 275ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#ifndef CURL_DISABLE_FTP 285ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsenextern const struct Curl_handler Curl_handler_ftp; 295ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 305ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#ifdef USE_SSL 315ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsenextern const struct Curl_handler Curl_handler_ftps; 325ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#endif 335ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 345ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian MonsenCURLcode Curl_ftpsendf(struct connectdata *, const char *fmt, ...); 355ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian MonsenCURLcode Curl_GetFTPResponse(ssize_t *nread, struct connectdata *conn, 365ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int *ftpcode); 375ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#endif /* CURL_DISABLE_FTP */ 385ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 395ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen/**************************************************************************** 405ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen * FTP unique setup 415ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen ***************************************************************************/ 425ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsentypedef enum { 435ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_STOP, /* do nothing state, stops the state machine */ 445ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_WAIT220, /* waiting for the initial 220 response immediately after 455ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen a connect */ 465ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_AUTH, 475ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_USER, 485ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PASS, 495ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_ACCT, 505ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PBSZ, 515ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PROT, 525ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_CCC, 535ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PWD, 545ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_SYST, 555ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_NAMEFMT, 565ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_QUOTE, /* waiting for a response to a command sent in a quote list */ 575ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_RETR_PREQUOTE, 585ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_STOR_PREQUOTE, 595ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_POSTQUOTE, 605ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_CWD, /* change dir */ 615ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_MKD, /* if the dir didn't exist */ 625ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_MDTM, /* to figure out the datestamp */ 635ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_TYPE, /* to set type when doing a head-like request */ 645ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_LIST_TYPE, /* set type when about to do a dir list */ 655ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_RETR_TYPE, /* set type when about to RETR a file */ 665ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_STOR_TYPE, /* set type when about to STOR a file */ 675ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_SIZE, /* get the remote file's size for head-like request */ 685ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_RETR_SIZE, /* get the remote file's size for RETR */ 69e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET FTP_STOR_SIZE, /* get the size for STOR */ 705ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_REST, /* when used to check if the server supports it in head-like */ 715ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_RETR_REST, /* when asking for "resume" in for RETR */ 725ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */ 735ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */ 745ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_PASV, /* generic state for PASV and EPSV, check count1 */ 755ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_LIST, /* generic state for LIST, NLST or a custom list command */ 765ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_RETR, 775ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_STOR, /* generic state for STOR and APPE */ 785ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_QUIT, 795ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTP_LAST /* never used */ 805ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen} ftpstate; 815ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 829bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsstruct ftp_parselist_data; /* defined later in ftplistparser.c */ 839bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 849bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsstruct ftp_wc_tmpdata { 859bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels struct ftp_parselist_data *parser; 869bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 879bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels struct { 889bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels curl_write_callback write_function; 899bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels FILE *file_descriptor; 909bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels } backup; 919bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}; 929bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels 935ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsentypedef enum { 945ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */ 955ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */ 96e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the 97e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET file */ 985ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen} curl_ftpfile; 995ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 100e3149cc1cf501b46caba8d47652ac90b95c78eacAlex Deymo/* This FTP struct is used in the Curl_easy. All FTP data that is 1015ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen connection-oriented must be in FTP_conn to properly deal with the fact that 102e3149cc1cf501b46caba8d47652ac90b95c78eacAlex Deymo perhaps the Curl_easy is changed between the times the connection is 1035ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen used. */ 1045ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsenstruct FTP { 1055ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen curl_off_t *bytecountp; 1065ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char *user; /* user name string */ 1075ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char *passwd; /* password string */ 1085ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 1095ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen /* transfer a file/body or not, done as a typedefed enum just to make 1105ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen debuggers display the full symbol and not just the numerical value */ 111e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET curl_pp_transfer transfer; 1125ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen curl_off_t downloadsize; 1135ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen}; 1145ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 1155ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 1165ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen/* ftp_conn is used for struct connection-oriented data in the connectdata 1175ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen struct */ 1185ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsenstruct ftp_conn { 1195ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen struct pingpong pp; 1205ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char *entrypath; /* the PWD reply when we logged on */ 1215ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char **dirs; /* realloc()ed array for path components */ 1225ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int dirdepth; /* number of entries used in the 'dirs' array */ 1235ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int diralloc; /* number of entries allocated for the 'dirs' array */ 1245ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char *file; /* decoded file */ 1255ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen bool dont_check; /* Set to TRUE to prevent the final (post-transfer) 1265ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen file size and 226/250 status check. It should still 1275ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen read the line, just ignore the result. */ 1285ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do anything. If 1295ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen the connection has timed out or been closed, this 1305ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen should be FALSE when it gets to Curl_ftp_quit() */ 1315ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen bool cwddone; /* if it has been determined that the proper CWD combo 1325ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen already has been done */ 1335ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent 1345ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen caching the current directory */ 135e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET bool wait_data_conn; /* this is set TRUE if data connection is waited */ 1365ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char *prevpath; /* conn->path from the previous transfer */ 1375ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a 1385ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen and others (A/I or zero) */ 1395ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int count1; /* general purpose counter for the state machine */ 1405ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int count2; /* general purpose counter for the state machine */ 1415ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen int count3; /* general purpose counter for the state machine */ 1425ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen ftpstate state; /* always use ftp.c:state() to change state! */ 143e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET ftpstate state_saved; /* transfer type saved to be reloaded after 144e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET data connection is established */ 145e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET curl_off_t retr_size_saved; /* Size of retrieved file saved */ 1465ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen char * server_os; /* The target server operating system. */ 1479bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels curl_off_t known_filesize; /* file size is different from -1, if wildcard 148e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET LIST parsing was done and wc_statemach set 149e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET it */ 150e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET /* newhost is the (allocated) IP addr or host name to connect the data 151e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET connection to */ 152e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET char *newhost; /* this is the pair to connect the DATA... */ 153e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET unsigned short newport; /* connection to */ 154e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET 1555ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen}; 1565ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen 157e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET#define DEFAULT_ACCEPT_TIMEOUT 60000 /* milliseconds == one minute */ 158e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET 1595ab5018bf8f0e39957d264f33c3eeddd958ed5d8Kristian Monsen#endif /* HEADER_CURL_FTP_H */ 160