ftp.h 6.4 KB

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