curl-library
RE: Help with partial file upload - result 18 - (0 bytes)
Date: Wed, 1 Nov 2006 15:41:19 -0700
Dan,
Thanks for the guidance. I have converted to buffered - fopen() and
fread(). I am now getting the following error message from the callback
function.
=================================================================
7 [main] curl 496572 _cygtls::handle_exceptions: Error while dumping state
(probably corrupted stack)
Segmentation fault (core dumped)
=================================================================
Here's the dump
Exception: STATUS_ACCESS_VIOLATION at eip=0040132B
eax=00000000 ebx=00423488 ecx=611000D8 edx=6110013C esi=0042BA98
edi=00000004
ebp=0022CB58 esp=0022CB30 program=d:\c_projects\curl.exe, pid 496572, thread
main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
0022CB58 0040132B (00427791, 00000001, 00004000, 00000000)
0022CB8C 61E12CA9 (0042BA98, 00004000, 0022CBDC, 0042BA98)
0022CBF8 61E13FB0 (0042BA98, 0022CC16, 0042BC08, 0022CC1C)
0022CC28 61E14CF3 (00423488, 0000002A, 00000001, 00000000)
0022CCE8 004015C7 (00000002, 61167CFC, 00BE0090, 0022CC80)
0022CD98 61006168 (00000000, 0022CDD0, 610054E0, 0022CDD0)
610054E0 61004416 (0000009C, A02404C7, E8610FF1, FFFFFF48)
7 [main] curl 496572 _cygtls::handle_exceptions: Error while dumping
state (probably corrupted stack)
================================================================
Here's the trace
== Info: About to connect() to ftp.vaultnow.com port 21
== Info: Trying 66.235.193.158... == Info: connected
== Info: Connected to ftp.vaultnow.com (66.235.193.158) port 21
<= Recv header, 53 bytes (0xzx)
000zx: 220---------- Welcome to Pure-FTPd [TLS] ----------
<= Recv header, 42 bytes (0xzx)
000zx: 220-You are user number 2 of 50 allowed.
<= Recv header, 47 bytes (0xzx)
000zx: 220-Local time is now 14:10. Server port: 21.
<= Recv header, 62 bytes (0xzx)
000zx: 220 You will be disconnected after 15 minutes of inactivity.
=> Send header, 28 bytes (0xzx)
000zx: USER user_name_at_vaultnow.com
<= Recv header, 54 bytes (0xzx)
000zx: 331 User site_ftp_at_domain_name.com OK. Password required
=> Send header, 15 bytes (0xzx)
000zx: PASS password
<= Recv header, 63 bytes (0xzx)
000zx: 230-User site_ftp_at_vaultnow.com has group access to: vaultnow
<= Recv header, 43 bytes (0xzx)
000zx: 230 OK. Current restricted directory is /
=> Send header, 5 bytes (0xzx)
000zx: PWD
<= Recv header, 34 bytes (0xzx)
000zx: 257 "/" is your current location
== Info: Entry path is '/'
=> Send header, 6 bytes (0xzx)
000zx: EPSV
== Info: Connect data stream passively
<= Recv header, 21 bytes (0xzx)
000zx: 500 Unknown command
== Info: disabling EPSV usage
=> Send header, 6 bytes (0xzx)
000zx: PASV
<= Recv header, 50 bytes (0xzx)
000zx: 227 Entering Passive Mode (66,235,193,158,32,30)
== Info: Trying 66.235.193.158... == Info: connected
== Info: Connecting to 66.235.193.158 (66.235.193.158) port 8222
=> Send header, 8 bytes (0xzx)
000zx: TYPE I
<= Recv header, 30 bytes (0xzx)
000zx: 200 TYPE is now 8-bit binary
=> Send header, 20 bytes (0xzx)
000zx: STOR stat_file.dat
<= Recv header, 30 bytes (0xzx)
000zx: 150 Accepted data connection
======================================================
Here's the source
/***************************************************************************
**
*
* project to get ftp in C working
*
*/
#define TRUE 1
#define FALSE 0
#include <stdio.h>
#include <curl/curl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define LOCAL_FILE "stat_file.dat"
#define UPLOAD_FILE_AS "stat_file.dat"
#define REMOTE_URL "ftp://ftp.domain.com/" UPLOAD_FILE_AS
#define RENAME_FILE_TO "stat_file.dat"
#define response_timeout 30
#define debug "debug"
FILE * hd_src ;
struct data {
char trace_ascii; /* 1 or 0 */
};
static
void dump(const char *text,
FILE *stream, unsigned char *ptr, size_t size,
char nohex)
{
size_t i;
size_t c;
unsigned int width=0x10;
if(nohex)
/* without the hex output, we can fit more on screen */
width = 0x40;
fprintf(stream, "%s, %d bytes (0x%zx)\n", text, size, size);
for(i=0; i<size; i+= width) {
fprintf(stream, "%04zx: ", i);
if(!nohex) {
/* hex not disabled, show it */
for(c = 0; c < width; c++)
if(i+c < size)
fprintf(stream, "%02x ", ptr[i+c]);
else
fputs(" ", stream);
}
for(c = 0; (c < width) && (i+c < size); c++) {
/* check for 0D0A; if found, skip past and start a new line of output
*/
if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
i+=(c+2-width);
break;
}
fprintf(stream, "%c",
(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
/* check again for 0D0A, to avoid an extra \n if it's at width */
if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
i+=(c+3-width);
break;
}
}
fputc('\n', stream); /* newline */
}
fflush(stream);
}
static
int my_trace(CURL *handle, curl_infotype type,
unsigned char *data, size_t size,
void *userp)
{
struct data *config = (struct data *)userp;
const char *text;
(void)handle; /* prevent compiler warning */
switch (type) {
case CURLINFO_TEXT:
fprintf(stderr, "== Info: %s", data);
default: /* in case a new one is introduced to shock us */
return 0;
case CURLINFO_HEADER_OUT:
text = "=> Send header";
break;
case CURLINFO_DATA_OUT:
text = "=> Send data";
break;
case CURLINFO_HEADER_IN:
text = "<= Recv header";
break;
case CURLINFO_DATA_IN:
text = "<= Recv data";
break;
case CURLINFO_SSL_DATA_IN:
text = "<= Recv SSL data";
break;
case CURLINFO_SSL_DATA_OUT:
text = "<= Send SSL data";
break;
}
dump(text, stderr, data, size, config->trace_ascii);
return 0;
}
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
FILE *f = stream;
size_t retcode;
printf("In read_callback function\n");
if (ferror(f))
return CURL_READFUNC_ABORT;
retcode = fread(ptr, size, nmemb, stream);
fprintf(stderr, "*** We read %d bytes from file\n", retcode);
return retcode;
}
int main(int argc, char **argv)
{
CURL *curl;
struct data config;
config.trace_ascii = 1; /* enable ascii tracing */
CURLcode res;
FILE *ftpfile;
int hd ;
int debug_flag;
int result;
struct stat file_info;
/* if first arg in call is "debug", then turn on debug tracing */
if (!strcmp(argv[1], debug) )
{
debug_flag = 1;
printf("debug flag set to 1\n");
}
if (debug_flag == TRUE)
printf("starting curl\n");
/* get the file size of the local file */
hd = open(LOCAL_FILE, O_RDONLY) ;
fstat(hd, &file_info);
close(hd) ;
if (debug_flag == TRUE)
printf("file size is: %d\n", file_info.st_size);
/* get a FILE * of the same file, could also be made with
fdopen() from the previous descriptor, but hey this is just
an example!
hd_src = fopen(LOCAL_FILE, "rb");
if (hd_src == NULL)
{
printf("File open failed. Exiting.\n");
exit (1);
}
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
/* specify target */
curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);
curl_easy_setopt(curl, CURLOPT_FTP_RESPONSE_TIMEOUT, response_timeout);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
/* Set the size of the file to upload (optional). If you give a *_LARGE
option you MUST make sure that the type of the passed-in argument is a
curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
make sure that to pass in a type 'long' argument. */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
curl_easy_setopt(curl, CURLOPT_USERPWD, "id_at_domian.com:password");
if (debug_flag == TRUE)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
printf("calling curl_easy_perform\n");
}
/* pass in that last of FTP commands to run after the transfer */
/* Now run off and do what you've been told! */
res = curl_easy_perform(curl);
if (debug_flag == TRUE)
printf("result is %d\n",res);
/* always cleanup */
curl_easy_cleanup(curl);
}
fclose(hd_src); /* close the local file */
curl_global_cleanup();
return 0;
}
=============================================================
Again, the OS is Server 2003.
Thanks in advance for any ongoing help.
Leon
Leon Vanderploeg
Phone: 720-922-7900
-----Original Message-----
From: curl-library-bounces_at_cool.haxx.se
[mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of Dan Fandrich
Sent: Tuesday, October 31, 2006 4:32 PM
To: curl-library_at_cool.haxx.se
Subject: Re: Help with partial file upload - result 18 - (0 bytes)
On Tue, Oct 31, 2006 at 03:50:54PM -0700, Leon Vanderploeg wrote:
> I am new to cURL, and am trying to make it work. I have been able to get
to
> a successful connection, but the file is always 0 bytes (result 18).
[...]
> size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
> {
> size_t retcode;
>
> int fd = (int)stream;
>
> printf("fd is %d: \n",fd);
>
> retcode = read(fd, ptr, size * nmemb);
[...]
> hd_src = fopen(LOCAL_FILE, "rb");
You're opening the file with fopen() but using read() to read from it.
That's
mixing metaphors. Either replace fopen() with open() or read() with
fread().
> hd = open(LOCAL_FILE, O_RDONLY) ;
> fstat(hd, &file_info);
> close(hd) ;
While we're here, you can use lstat() here and avoid the superfluous
open/close.
> curl_easy_setopt(curl, CURLOPT_USERPWD, "simple_at_vaultnow.com:s1mpl3");
I hope this isn't your real password, or it is now very simple for
someone to break in to your account.
>>> Dan
-- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has movedReceived on 2006-11-01