1#ifndef HEADER_CURL_FTP_H
2#define HEADER_CURL_FTP_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ***************************************************************************/
24
25#include "pingpong.h"
26
27#ifndef CURL_DISABLE_FTP
28extern const struct Curl_handler Curl_handler_ftp;
29
30#ifdef USE_SSL
31extern const struct Curl_handler Curl_handler_ftps;
32#endif
33
34CURLcode Curl_GetFTPResponse(struct Curl_easy *data, ssize_t *nread,
35 int *ftpcode);
36#endif /* CURL_DISABLE_FTP */
37
38/****************************************************************************
39 * FTP unique setup
40 ***************************************************************************/
41typedef enum {
42 FTP_STOP, /* do nothing state, stops the state machine */
43 FTP_WAIT220, /* waiting for the initial 220 response immediately after
44 a connect */
45 FTP_AUTH,
46 FTP_USER,
47 FTP_PASS,
48 FTP_ACCT,
49 FTP_PBSZ,
50 FTP_PROT,
51 FTP_CCC,
52 FTP_PWD,
53 FTP_SYST,
54 FTP_NAMEFMT,
55 FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
56 FTP_RETR_PREQUOTE,
57 FTP_STOR_PREQUOTE,
58 FTP_POSTQUOTE,
59 FTP_CWD, /* change dir */
60 FTP_MKD, /* if the dir didn't exist */
61 FTP_MDTM, /* to figure out the datestamp */
62 FTP_TYPE, /* to set type when doing a head-like request */
63 FTP_LIST_TYPE, /* set type when about to do a dir list */
64 FTP_RETR_TYPE, /* set type when about to RETR a file */
65 FTP_STOR_TYPE, /* set type when about to STOR a file */
66 FTP_SIZE, /* get the remote file's size for head-like request */
67 FTP_RETR_SIZE, /* get the remote file's size for RETR */
68 FTP_STOR_SIZE, /* get the size for STOR */
69 FTP_REST, /* when used to check if the server supports it in head-like */
70 FTP_RETR_REST, /* when asking for "resume" in for RETR */
71 FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
72 FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */
73 FTP_PASV, /* generic state for PASV and EPSV, check count1 */
74 FTP_LIST, /* generic state for LIST, NLST or a custom list command */
75 FTP_RETR,
76 FTP_STOR, /* generic state for STOR and APPE */
77 FTP_QUIT,
78 FTP_LAST /* never used */
79} ftpstate;
80
81struct ftp_parselist_data; /* defined later in ftplistparser.c */
82
83struct ftp_wc {
84 struct ftp_parselist_data *parser;
85
86 struct {
87 curl_write_callback write_function;
88 FILE *file_descriptor;
89 } backup;
90};
91
92typedef enum {
93 FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */
94 FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */
95 FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the
96 file */
97} curl_ftpfile;
98
99/* This FTP struct is used in the Curl_easy. All FTP data that is
100 connection-oriented must be in FTP_conn to properly deal with the fact that
101 perhaps the Curl_easy is changed between the times the connection is
102 used. */
103struct FTP {
104 char *path; /* points to the urlpieces struct field */
105 char *pathalloc; /* if non-NULL a pointer to an allocated path */
106
107 /* transfer a file/body or not, done as a typedefed enum just to make
108 debuggers display the full symbol and not just the numerical value */
109 curl_pp_transfer transfer;
110 curl_off_t downloadsize;
111};
112
113
114/* ftp_conn is used for struct connection-oriented data in the connectdata
115 struct */
116struct ftp_conn {
117 struct pingpong pp;
118 char *entrypath; /* the PWD reply when we logged on */
119 char *file; /* url-decoded file name (or path) */
120 char **dirs; /* realloc()ed array for path components */
121 int dirdepth; /* number of entries used in the 'dirs' array */
122 bool dont_check; /* Set to TRUE to prevent the final (post-transfer)
123 file size and 226/250 status check. It should still
124 read the line, just ignore the result. */
125 bool ctl_valid; /* Tells Curl_ftp_quit() whether or not to do anything. If
126 the connection has timed out or been closed, this
127 should be FALSE when it gets to Curl_ftp_quit() */
128 bool cwddone; /* if it has been determined that the proper CWD combo
129 already has been done */
130 int cwdcount; /* number of CWD commands issued */
131 bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent
132 caching the current directory */
133 bool wait_data_conn; /* this is set TRUE if data connection is waited */
134 /* newhost is the (allocated) IP addr or host name to connect the data
135 connection to */
136 unsigned short newport;
137 char *newhost;
138 char *prevpath; /* url-decoded conn->path from the previous transfer */
139 char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
140 and others (A/I or zero) */
141 int count1; /* general purpose counter for the state machine */
142 int count2; /* general purpose counter for the state machine */
143 int count3; /* general purpose counter for the state machine */
144 ftpstate state; /* always use ftp.c:state() to change state! */
145 ftpstate state_saved; /* transfer type saved to be reloaded after
146 data connection is established */
147 curl_off_t retr_size_saved; /* Size of retrieved file saved */
148 char *server_os; /* The target server operating system. */
149 curl_off_t known_filesize; /* file size is different from -1, if wildcard
150 LIST parsing was done and wc_statemach set
151 it */
152};
153
154#define DEFAULT_ACCEPT_TIMEOUT 60000 /* milliseconds == one minute */
155
156#endif /* HEADER_CURL_FTP_H */
157