ftp.h 6.7 KB

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