Newer
Older
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
Daniel Stenberg
committed
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
***************************************************************************/
#ifndef CURL_DISABLE_FTP
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifndef WIN32
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include <inet.h>
#endif
#endif /* !WIN32 */
#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
#undef in_addr_t
#define in_addr_t unsigned long
#endif
#include <curl/curl.h>
#include "urldata.h"
#include "sendf.h"
#include "easyif.h" /* for Curl_convert_... prototypes */
#include "if2ip.h"
#include "hostip.h"
#include "progress.h"
Daniel Stenberg
committed
#include "transfer.h"
#include "http.h" /* for HTTP proxy tunnel stuff */
#include "ftp.h"
#if defined(HAVE_KRB4) || defined(HAVE_GSSAPI)
#include "krb4.h"
Daniel Stenberg
committed
#include "sslgen.h"
Daniel Stenberg
committed
#include "inet_ntop.h"
#include "inet_pton.h"
#include "parsedate.h" /* for the week day and month names */
Daniel Stenberg
committed
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
Daniel Stenberg
committed
#include "multiif.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
/* The last #include file should be: */
#include "memdebug.h"
#ifdef HAVE_NI_WITHSCOPEID
Daniel Stenberg
committed
#define NIFLAGS NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID
#else
#define NIFLAGS NI_NUMERICHOST | NI_NUMERICSERV
#endif
#ifdef __SYMBIAN32__
/* Symbian OS panics when given a timeout much greater than 1/2 hour */
#define RESP_TIMEOUT (1800*1000)
#else
/* Default response timeout in milliseconds */
#define RESP_TIMEOUT (3600*1000)
static CURLcode ftp_sendquote(struct connectdata *conn,
struct curl_slist *quote);
Daniel Stenberg
committed
static CURLcode ftp_quit(struct connectdata *conn);
Daniel Stenberg
committed
static CURLcode ftp_parse_url_path(struct connectdata *conn);
static CURLcode ftp_regular_transfer(struct connectdata *conn, bool *done);
static void ftp_pasv_verbose(struct connectdata *conn,
Curl_addrinfo *ai,
char *newhost, /* ascii version */
int port);
static CURLcode ftp_state_post_rest(struct connectdata *conn);
static CURLcode ftp_state_post_cwd(struct connectdata *conn);
static CURLcode ftp_state_quote(struct connectdata *conn,
bool init, ftpstate instate);
Daniel Stenberg
committed
static CURLcode ftp_nb_type(struct connectdata *conn,
bool ascii, ftpstate newstate);
Daniel Stenberg
committed
static int ftp_need_type(struct connectdata *conn,
bool ascii);
static CURLcode ftp_do(struct connectdata *conn, bool *done);
static CURLcode ftp_done(struct connectdata *conn,
Patrick Monnerat
committed
CURLcode, bool premature);
static CURLcode ftp_connect(struct connectdata *conn, bool *done);
static CURLcode ftp_disconnect(struct connectdata *conn);
static CURLcode ftp_nextconnect(struct connectdata *conn);
static CURLcode ftp_multi_statemach(struct connectdata *conn, bool *done);
static int ftp_getsock(struct connectdata *conn,
Patrick Monnerat
committed
curl_socket_t *socks,
int numsocks);
static CURLcode ftp_doing(struct connectdata *conn,
Patrick Monnerat
committed
bool *dophase_done);
static CURLcode ftp_setup_connection(struct connectdata * conn);
#ifdef USE_SSL
static CURLcode ftps_setup_connection(struct connectdata * conn);
#endif
/* easy-to-use macro: */
Daniel Stenberg
committed
#define FTPSENDF(x,y,z) if((result = Curl_ftpsendf(x,y,z)) != CURLE_OK) \
Gisle Vanem
committed
return result
Daniel Stenberg
committed
#define NBFTPSENDF(x,y,z) if((result = Curl_nbftpsendf(x,y,z)) != CURLE_OK) \
Gisle Vanem
committed
return result
Patrick Monnerat
committed
/*
* FTP protocol handler.
*/
const struct Curl_handler Curl_handler_ftp = {
"FTP", /* scheme */
ftp_setup_connection, /* setup_connection */
ftp_do, /* do_it */
ftp_done, /* done */
ftp_nextconnect, /* do_more */
ftp_connect, /* connect_it */
ftp_multi_statemach, /* connecting */
ftp_doing, /* doing */
ftp_getsock, /* proto_getsock */
ftp_getsock, /* doing_getsock */
ftp_disconnect, /* disconnect */
Patrick Monnerat
committed
PORT_FTP, /* defport */
PROT_FTP /* protocol */
};
#ifdef USE_SSL
/*
* FTPS protocol handler.
*/
const struct Curl_handler Curl_handler_ftps = {
"FTPS", /* scheme */
ftps_setup_connection, /* setup_connection */
ftp_do, /* do_it */
ftp_done, /* done */
ftp_nextconnect, /* do_more */
ftp_connect, /* connect_it */
ftp_multi_statemach, /* connecting */
ftp_doing, /* doing */
ftp_getsock, /* proto_getsock */
ftp_getsock, /* doing_getsock */
Loading
Loading full blame...