Newer
Older
Daniel Stenberg
committed
FTPSENDF(conn, "REST %" FORMAT_OFF_T, conn->resume_from);
Daniel Stenberg
committed
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if(result)
return result;
if(ftpcode != 350) {
Daniel Stenberg
committed
FTPSENDF(conn, "RETR %s", ftp->file);
Daniel Stenberg
committed
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if(result)
return result;
if((ftpcode == 150) || (ftpcode == 125)) {
/*
A;
150 Opening BINARY mode data connection for /etc/passwd (2241
bytes). (ok, the file is being transfered)
150 Opening ASCII mode data connection for /bin/ls
C:
150 ASCII data connection for /bin/ls (137.167.104.91,37445) (0 bytes).
D:
150 Opening ASCII mode data connection for /linux/fisk/kpanelrc (0.0.0.0,0) (545 bytes).
E:
125 Data connection already open; Transfer starting. */
curl_off_t size=-1; /* default unknown size */
/*
* It appears that there are FTP-servers that return size 0 for files
* when SIZE is used on the file while being in BINARY mode. To work
* around that (stupid) behavior, we attempt to parse the RETR response
* even if the SIZE returned size zero.
*
* Debugging help from Salvatore Sorrentino on February 26, 2003.
*/
Daniel Stenberg
committed
if(!dirlist &&
Daniel Stenberg
committed
!data->set.ftp_ascii &&
(downloadsize < 1)) {
/*
* It seems directory listings either don't show the size or very
Daniel Stenberg
committed
* often uses size 0 anyway. ASCII transfers may very well turn out
* that the transfered amount of data is not the same as this line
* tells, why using this number in those cases only confuses us.
*
* Example D above makes this parsing a little tricky */
char *bytes;
bytes=strstr(buf, " bytes");
if(bytes--) {
/* this is a hint there is size information in there! ;-) */
/* scan for the parenthesis and break there */
if('(' == *bytes)
break;
/* if only skip digits, or else we're in deep trouble */
if(!isdigit((int)*bytes)) {
bytes=NULL;
break;
}
/* one more estep backwards */
bytes--;
}
/* only if we have nothing but digits: */
if(bytes++) {
/* get the number! */
Daniel Stenberg
committed
size = curlx_strtoofft(bytes, NULL, 0);
}
}
else if(downloadsize > -1)
size = downloadsize;
Daniel Stenberg
committed
if(data->set.ftp_use_port) {
Daniel Stenberg
committed
result = AllowServerConnect(conn);
Daniel Stenberg
committed
if(conn->ssl[SECONDARYSOCKET].use) {
/* since we only have a plaintext TCP connection here, we must now
do the TLS stuff */
infof(data, "Doing the SSL/TLS handshake on the data stream\n");
result = Curl_SSLConnect(conn, SECONDARYSOCKET);
if(result)
return result;
Daniel Stenberg
committed
}
if(size > conn->maxdownload && conn->maxdownload > 0)
Daniel Stenberg
committed
size = conn->size = conn->maxdownload;
Daniel Stenberg
committed
infof(data, "Getting file with size: %" FORMAT_OFF_T "\n", size);
Daniel Stenberg
committed
result=Curl_Transfer(conn, SECONDARYSOCKET, size, FALSE,
bytecountp,
-1, NULL); /* no upload here */
if(dirlist && (ftpcode == 450)) {
/* simply no matching files */
ftp->no_transfer = TRUE; /* don't think we should download anything */
}
else {
failf(data, "%s", buf+4);
return CURLE_FTP_COULDNT_RETR_FILE;
}
/***********************************************************************
*
* ftp_perform()
*
* This is the actual DO function for FTP. Get a file/directory according to
* the options previously setup.
*/
static
CURLcode ftp_perform(struct connectdata *conn,
bool *connected) /* for the TCP connect status after
PASV / PORT */
{
/* this is FTP and no proxy */
CURLcode result=CURLE_OK;
struct SessionHandle *data=conn->data;
char *buf = data->state.buffer; /* this is our buffer */
Daniel Stenberg
committed
/* the ftp struct is already inited in Curl_ftp_connect() */
struct FTP *ftp = conn->proto.ftp;
/* Send any QUOTE strings? */
if(data->set.quote) {
if ((result = ftp_sendquote(conn, data->set.quote)) != CURLE_OK)
return result;
}
Daniel Stenberg
committed
result = ftp_cwd_and_create_path(conn);
if (result)
return result;
/* Requested time of file or time-depended transfer? */
if((data->set.get_filetime || data->set.timecondition) &&
ftp->file) {
result = ftp_getfiletime(conn, ftp->file);
switch( result )
{
case CURLE_FTP_COULDNT_RETR_FILE:
case CURLE_OK:
if(data->set.timecondition) {
if((data->info.filetime > 0) && (data->set.timevalue > 0)) {
switch(data->set.timecondition) {
case CURL_TIMECOND_IFMODSINCE:
default:
if(data->info.filetime < data->set.timevalue) {
infof(data, "The requested document is not new enough\n");
ftp->no_transfer = TRUE; /* mark this to not transfer data */
return CURLE_OK;
}
break;
case CURL_TIMECOND_IFUNMODSINCE:
if(data->info.filetime > data->set.timevalue) {
infof(data, "The requested document is not old enough\n");
ftp->no_transfer = TRUE; /* mark this to not transfer data */
return CURLE_OK;
}
break;
} /* switch */
else {
infof(data, "Skipping time comparison\n");
}
break;
default:
return result;
} /* switch */
}
/* If we have selected NOBODY and HEADER, it means that we only want file
information. Which in FTP can't be much more than the file size and
date. */
Daniel Stenberg
committed
if(conn->bits.no_body && data->set.include_header && ftp->file) {
/* The SIZE command is _not_ RFC 959 specified, and therefor many servers
may not support it! It is however the only way we have to get a file's
size! */
Daniel Stenberg
committed
ssize_t nread;
int ftpcode;
ftp->no_transfer = TRUE; /* this means no actual transfer is made */
/* Some servers return different sizes for different modes, and thus we
must set the proper type before we check the size */
result = ftp_transfertype(conn, data->set.ftp_ascii);
if(result)
return result;
/* failing to get size is not a serious error */
result = ftp_getsize(conn, ftp->file, &filesize);
if(CURLE_OK == result) {
snprintf(buf, sizeof(data->state.buffer),
"Content-Length: %" FORMAT_OFF_T "\r\n", filesize);
result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result)
return result;
}
Daniel Stenberg
committed
/* Determine if server can respond to REST command and therefore
whether it can do a range */
FTPSENDF(conn, "REST 0", NULL);
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if ((CURLE_OK == result) && (ftpcode == 350)) {
result = Curl_client_write(data, CLIENTWRITE_BOTH,
(char *)"Accept-ranges: bytes\r\n", 0);
if(result)
return result;
}
/* If we asked for a time of the file and we actually got one as
well, we "emulate" a HTTP-style header in our output. */
#ifdef HAVE_STRFTIME
if(data->set.get_filetime && (data->info.filetime>=0) ) {
struct tm *tm;
time_t clock = (time_t)data->info.filetime;
struct tm buffer;
tm = (struct tm *)gmtime_r(&clock, &buffer);
#else
tm = gmtime(&clock);
#endif
Daniel Stenberg
committed
/* format: "Tue, 15 Nov 1994 12:45:26" */
strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n",
tm);
result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result)
return result;
}
#endif
return CURLE_OK;
}
Daniel Stenberg
committed
if(conn->bits.no_body)
/* doesn't really transfer any data */
ftp->no_transfer = TRUE;
/* Get us a second connection up and connected */
else if(data->set.ftp_use_port) {
/* We have chosen to use the PORT command */
result = ftp_use_port(conn);
if(CURLE_OK == result) {
/* we have the data connection ready */
infof(data, "Ordered connect of the data stream with PORT!\n");
*connected = TRUE; /* mark us "still connected" */
}
}
else {
/* We have chosen (this is default) to use the PASV command */
result = ftp_use_pasv(conn, connected);
if(CURLE_OK == result && *connected)
infof(data, "Connected the data stream with PASV!\n");
}
return result;
}
/***********************************************************************
*
* Curl_ftp()
*
* This function is registered as 'curl_do' function. It decodes the path
* parts etc as a wrapper to the actual DO function (ftp_perform).
*
* The input argument is already checked for validity.
*/
CURLcode Curl_ftp(struct connectdata *conn)
CURLcode retcode = CURLE_OK;
Daniel Stenberg
committed
Daniel Stenberg
committed
retcode = ftp_parse_url_path(conn);
if (retcode)
return retcode;
if (conn->sec_conn) /* 3rd party transfer */
retcode = ftp_3rdparty(conn);
retcode = ftp_regular_transfer(conn);
Daniel Stenberg
committed
/***********************************************************************
*
* Curl_ftpsendf()
*
* Sends the formated string as a ftp command to a ftp server
*
* NOTE: we build the command in a fixed-length buffer, which sets length
* restrictions on the command!
*/
Daniel Stenberg
committed
CURLcode Curl_ftpsendf(struct connectdata *conn,
const char *fmt, ...)
ssize_t bytes_written;
char s[256];
char *sptr=s;
CURLcode res = CURLE_OK;
va_list ap;
va_start(ap, fmt);
vsnprintf(s, 250, fmt, ap);
va_end(ap);
strcat(s, "\r\n"); /* append a trailing CRLF */
Daniel Stenberg
committed
write_len = strlen(s);
while(1) {
Daniel Stenberg
committed
res = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len,
&bytes_written);
if(CURLE_OK != res)
break;
if(conn->data->set.verbose)
Curl_debug(conn->data, CURLINFO_HEADER_OUT, sptr, bytes_written, conn->host.dispname);
if(bytes_written != (ssize_t)write_len) {
write_len -= bytes_written;
sptr += bytes_written;
}
else
break;
}
return res;
}
/***********************************************************************
*
Daniel Stenberg
committed
* ftp_quit()
*
* This should be called before calling sclose() on an ftp control connection
* (not data connections). We should then wait for the response from the
* server before returning. The calling code should then try to close the
* connection.
*
*/
Daniel Stenberg
committed
static CURLcode ftp_quit(struct connectdata *conn)
{
ssize_t nread;
int ftpcode;
CURLcode ret = CURLE_OK;
if(conn->proto.ftp->ctl_valid) {
ret = Curl_ftpsendf(conn, "%s", "QUIT");
if(CURLE_OK == ret)
ret = Curl_GetFTPResponse(&nread, conn, &ftpcode);
}
return ret;
}
/***********************************************************************
*
* Curl_ftp_disconnect()
*
* Disconnect from an FTP server. Cleanup protocol-specific per-connection
* resources
*/
CURLcode Curl_ftp_disconnect(struct connectdata *conn)
{
struct FTP *ftp= conn->proto.ftp;
/* We cannot send quit unconditionally. If this connection is stale or
bad in any way, sending quit and waiting around here will make the
disconnect wait in vain and cause more problems than we need to.
Daniel Stenberg
committed
ftp_quit() will check the state of ftp->ctl_valid. If it's ok it
will try to send the QUIT command, otherwise it will just return.
*/
Daniel Stenberg
committed
/* The FTP session may or may not have been allocated/setup at this point! */
if(ftp) {
Daniel Stenberg
committed
(void)ftp_quit(conn); /* ignore errors on the QUIT */
Daniel Stenberg
committed
Daniel Stenberg
committed
if(ftp->entrypath)
free(ftp->entrypath);
if(ftp->cache) {
free(ftp->cache);
ftp->cache = NULL;
}
freedirs(ftp);
Daniel Stenberg
committed
}
Sterling Hughes
committed
/***********************************************************************
*
* ftp_mkd()
*
* Makes a directory on the FTP server.
*/
static CURLcode ftp_mkd(struct connectdata *conn, char *path)
{
CURLcode result=CURLE_OK;
int ftpcode; /* for ftp status */
ssize_t nread;
/* Create a directory on the remote server */
FTPSENDF(conn, "MKD %s", path);
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if(result)
return result;
switch(ftpcode) {
case 257:
/* success! */
infof( conn->data , "Created remote directory %s\n" , path );
break;
case 550:
failf(conn->data, "Permission denied to make directory %s", path);
result = CURLE_FTP_ACCESS_DENIED;
break;
default:
failf(conn->data, "unrecognized MKD response: %d", ftpcode );
result = CURLE_FTP_ACCESS_DENIED;
break;
}
return result;
}
/***********************************************************************
*
* ftp_cwd()
*
* Send 'CWD' to the remote server to Change Working Directory. It is the ftp
* version of the unix 'cd' command. This function is only called from the
* ftp_cwd_and_mkd() function these days.
*
* This function does NOT call failf().
*/
static
CURLcode ftp_cwd(struct connectdata *conn, char *path)
{
ssize_t nread;
int ftpcode;
CURLcode result;
FTPSENDF(conn, "CWD %s", path);
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if (!result) {
/* According to RFC959, CWD is supposed to return 250 on success, but
there seem to be non-compliant FTP servers out there that return 200,
so we accept any '2xy' code here. */
if (ftpcode/100 != 2)
result = CURLE_FTP_ACCESS_DENIED;
}
return result;
}
/***********************************************************************
*
* ftp_cwd_and_mkd()
*
* Change to the given directory. If the directory is not present, and we
* have been told to allow it, then create the directory and cd to it.
*/
static CURLcode ftp_cwd_and_mkd(struct connectdata *conn, char *path)
{
CURLcode result;
result = ftp_cwd(conn, path);
if (result) {
if(conn->data->set.ftp_create_missing_dirs) {
result = ftp_mkd(conn, path);
if (result)
/* ftp_mkd() calls failf() itself */
return result;
result = ftp_cwd(conn, path);
}
if(result)
failf(conn->data, "Couldn't CWD to %s", path);
}
return result;
}
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
/***********************************************************************
*
* ftp_3rdparty_pretransfer()
*
* Preparation for 3rd party transfer.
*
*/
static CURLcode ftp_3rdparty_pretransfer(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
struct connectdata *sec_conn = conn->sec_conn;
/* sets transfer type */
result = ftp_transfertype(conn, data->set.ftp_ascii);
if (result)
return result;
result = ftp_transfertype(sec_conn, data->set.ftp_ascii);
if (result)
return result;
/* Send any PREQUOTE strings after transfer type is set? */
if (data->set.source_prequote) {
/* sends command(s) to source server before file transfer */
result = ftp_sendquote(sec_conn, data->set.source_prequote);
}
if (!result && data->set.prequote)
result = ftp_sendquote(conn, data->set.prequote);
return result;
}
/***********************************************************************
*
* ftp_3rdparty_transfer()
*
* Performs 3rd party transfer.
*
*/
static CURLcode ftp_3rdparty_transfer(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
ssize_t nread;
int ftpcode, ip[4], port[2];
struct SessionHandle *data = conn->data;
struct connectdata *sec_conn = conn->sec_conn;
char *buf = data->state.buffer; /* this is our buffer */
char *str = buf;
char pasv_port[50];
const char *stor_cmd;
struct connectdata *pasv_conn;
struct connectdata *port_conn;
if (data->set.pasvHost == CURL_TARGET_PASV) {
pasv_conn = conn;
port_conn = sec_conn;
}
else {
pasv_conn = sec_conn;
port_conn = conn;
}
Daniel Stenberg
committed
result = ftp_cwd_and_create_path(conn);
if (result)
return result;
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
/* sets the passive mode */
FTPSENDF(pasv_conn, "%s", "PASV");
result = Curl_GetFTPResponse(&nread, pasv_conn, &ftpcode);
if (result) return result;
if (ftpcode != 227) {
failf(data, "Odd return code after PASV:%s", buf + 3);
return CURLE_FTP_WEIRD_PASV_REPLY;
}
while (*str) {
if (6 == sscanf(str, "%d,%d,%d,%d,%d,%d",
&ip[0], &ip[1], &ip[2], &ip[3], &port[0], &port[1]))
break;
str++;
}
if (!*str) {
failf(pasv_conn->data, "Couldn't interpret this 227-reply: %s", buf);
return CURLE_FTP_WEIRD_227_FORMAT;
}
snprintf(pasv_port, sizeof(pasv_port), "%d,%d,%d,%d,%d,%d", ip[0], ip[1],
ip[2], ip[3], port[0], port[1]);
/* sets data connection between remote hosts */
FTPSENDF(port_conn, "PORT %s", pasv_port);
result = Curl_GetFTPResponse(&nread, port_conn, &ftpcode);
if (result)
return result;
if (ftpcode != 200) {
failf(data, "PORT command attempts failed:%s", buf + 3);
return CURLE_FTP_PORT_FAILED;
}
/* we might append onto the file instead of overwriting it */
stor_cmd = data->set.ftp_append?"APPE":"STOR";
/* transfers file between remote hosts */
FTPSENDF(sec_conn, "RETR %s", data->set.source_path);
if(data->set.pasvHost == CURL_TARGET_PASV) {
result = Curl_GetFTPResponse(&nread, sec_conn, &ftpcode);
if (result)
return result;
if (ftpcode != 150) {
failf(data, "Failed RETR: %s", buf + 4);
return CURLE_FTP_COULDNT_RETR_FILE;
}
result = Curl_ftpsendf(conn, "%s %s", stor_cmd, conn->path);
if(CURLE_OK == result)
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if (result)
return result;
if (ftpcode != 150) {
failf(data, "Failed FTP upload: %s", buf + 4);
return CURLE_FTP_COULDNT_STOR_FILE;
}
}
else {
result = Curl_ftpsendf(conn, "%s %s", stor_cmd, conn->path);
if(CURLE_OK == result)
result = Curl_GetFTPResponse(&nread, sec_conn, &ftpcode);
if (result)
return result;
if (ftpcode != 150) {
failf(data, "Failed FTP upload: %s", buf + 4);
return CURLE_FTP_COULDNT_STOR_FILE;
}
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if (result)
return result;
if (ftpcode != 150) {
failf(data, "Failed FTP upload: %s", buf + 4);
return CURLE_FTP_COULDNT_STOR_FILE;
}
}
return CURLE_OK;
}
/***********************************************************************
*
Daniel Stenberg
committed
* ftp_parse_url_path()
Daniel Stenberg
committed
* Parse the URL path into separate path components.
*
*/
static
Daniel Stenberg
committed
CURLcode ftp_parse_url_path(struct connectdata *conn)
Daniel Stenberg
committed
CURLcode retcode = CURLE_OK;
struct SessionHandle *data = conn->data;
struct FTP *ftp;
char *slash_pos; /* position of the first '/' char in curpos */
Daniel Stenberg
committed
char *cur_pos = conn->path; /* current position in path. point at the begin
of next path component */
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
/* the ftp struct is already inited in ftp_connect() */
ftp = conn->proto.ftp;
ftp->ctl_valid = FALSE;
ftp->dirdepth = 0;
ftp->diralloc = 5; /* default dir depth to allocate */
ftp->dirs = (char **)malloc(ftp->diralloc * sizeof(ftp->dirs[0]));
if(!ftp->dirs)
return CURLE_OUT_OF_MEMORY;
ftp->dirs[0] = NULL; /* to start with */
/* parse the URL path into separate path components */
while((slash_pos=strchr(cur_pos, '/'))) {
/* 1 or 0 to indicate absolute directory */
bool absolute_dir = (cur_pos - conn->path > 0) && (ftp->dirdepth == 0);
/* seek out the next path component */
if (slash_pos-cur_pos) {
/* we skip empty path components, like "x//y" since the FTP command CWD
requires a parameter and a non-existant parameter a) doesn't work on
many servers and b) has no effect on the others. */
int len = (int)(slash_pos - cur_pos + absolute_dir);
ftp->dirs[ftp->dirdepth] = curl_unescape(cur_pos - absolute_dir, len);
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
if (!ftp->dirs[ftp->dirdepth]) { /* run out of memory ... */
failf(data, "no memory");
freedirs(ftp);
return CURLE_OUT_OF_MEMORY;
}
}
else {
cur_pos = slash_pos + 1; /* jump to the rest of the string */
continue;
}
if(!retcode) {
cur_pos = slash_pos + 1; /* jump to the rest of the string */
if(++ftp->dirdepth >= ftp->diralloc) {
/* enlarge array */
char *bigger;
ftp->diralloc *= 2; /* double the size each time */
bigger = realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
if(!bigger) {
freedirs(ftp);
return CURLE_OUT_OF_MEMORY;
}
ftp->dirs = (char **)bigger;
}
}
}
ftp->file = cur_pos; /* the rest is the file name */
if(*ftp->file) {
ftp->file = curl_unescape(ftp->file, 0);
if(NULL == ftp->file) {
freedirs(ftp);
failf(data, "no memory");
return CURLE_OUT_OF_MEMORY;
}
}
else
ftp->file=NULL; /* instead of point to a zero byte, we make it a NULL
pointer */
dlen = conn->path?strlen(conn->path):0;
if(dlen && ftp->prevpath) {
dlen -= ftp->file?strlen(ftp->file):0;
if((dlen == strlen(ftp->prevpath)) &&
curl_strnequal(conn->path, ftp->prevpath, dlen)) {
infof(data, "Request has same path as previous transfer\n");
ftp->cwddone = TRUE;
Daniel Stenberg
committed
return retcode;
}
/***********************************************************************
*
* ftp_cwd_and_create_path()
*
* Creates full path on remote target host.
*
*/
static
CURLcode ftp_cwd_and_create_path(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
/* the ftp struct is already inited in Curl_ftp_connect() */
struct FTP *ftp = conn->proto.ftp;
int i;
if(ftp->cwddone)
/* already done and fine */
return CURLE_OK;
Daniel Stenberg
committed
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
/* This is a re-used connection. Since we change directory to where the
transfer is taking place, we must now get back to the original dir
where we ended up after login: */
if (conn->bits.reuse && ftp->entrypath) {
if ((result = ftp_cwd_and_mkd(conn, ftp->entrypath)) != CURLE_OK)
return result;
}
for (i=0; i < ftp->dirdepth; i++) {
/* RFC 1738 says empty components should be respected too, but
that is plain stupid since CWD can't be used with an empty argument */
if ((result = ftp_cwd_and_mkd(conn, ftp->dirs[i])) != CURLE_OK)
return result;
}
return result;
}
/***********************************************************************
*
* ftp_regular_transfer()
*
* The input argument is already checked for validity.
* Performs a regular transfer between local and remote hosts.
*
* ftp->ctl_valid starts out as FALSE, and gets set to TRUE if we reach the
* Curl_ftp_done() function without finding any major problem.
*/
static
CURLcode ftp_regular_transfer(struct connectdata *conn)
{
CURLcode retcode=CURLE_OK;
bool connected=0;
struct SessionHandle *data = conn->data;
struct FTP *ftp;
/* the ftp struct is already inited in ftp_connect() */
ftp = conn->proto.ftp;
conn->size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
Curl_pgrsSetUploadSize(data, 0);
Curl_pgrsSetDownloadSize(data, 0);
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
retcode = ftp_perform(conn, &connected);
if(CURLE_OK == retcode) {
if(connected)
retcode = Curl_ftp_nextconnect(conn);
if(retcode && (conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD)) {
/* Failure detected, close the second socket if it was created already */
sclose(conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
}
if(ftp->no_transfer)
/* no data to transfer */
retcode=Curl_Transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
else if(!connected)
/* since we didn't connect now, we want do_more to get called */
conn->bits.do_more = TRUE;
}
else
freedirs(ftp);
ftp->ctl_valid = TRUE; /* seems good */
return retcode;
}
/***********************************************************************
*
* ftp_3rdparty()
*
* The input argument is already checked for validity.
* Performs a 3rd party transfer between two remote hosts.
*/
static CURLcode ftp_3rdparty(struct connectdata *conn)
{
CURLcode retcode = CURLE_OK;
conn->proto.ftp->ctl_valid = conn->sec_conn->proto.ftp->ctl_valid = TRUE;
conn->size = conn->sec_conn->size = -1;
retcode = ftp_3rdparty_pretransfer(conn);
if (!retcode)
retcode = ftp_3rdparty_transfer(conn);
return retcode;
}
#endif /* CURL_DISABLE_FTP */