Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
d5e90413
Commit
d5e90413
authored
18 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
The new ftpuploadresume.c example by Philip Bock
parent
d99c20f6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/examples/Makefile.am
+1
-1
1 addition, 1 deletion
docs/examples/Makefile.am
docs/examples/ftpuploadresume.c
+154
-0
154 additions, 0 deletions
docs/examples/ftpuploadresume.c
with
155 additions
and
1 deletion
docs/examples/Makefile.am
+
1
−
1
View file @
d5e90413
...
...
@@ -11,7 +11,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \
multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c
\
multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c
\
anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c
\
cookie_interface.c cacertinmem.c synctime.c sampleconv.c
cookie_interface.c cacertinmem.c synctime.c sampleconv.c
ftpuploadresume.c
all
:
@
echo
"done"
This diff is collapsed.
Click to expand it.
docs/examples/ftpuploadresume.c
0 → 100644
+
154
−
0
View file @
d5e90413
/*****************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* $Id$
*
* Upload to FTP, resuming failed transfers
*
* Compile for MinGW like this:
* gcc -Wall -pedantic -std=c99 ftpuploadwithresume.c -o ftpuploadresume.exe
* -lcurl -lmsvcr70
*
* Written by Philip Bock
*/
#include
<stdlib.h>
#include
<stdio.h>
#include
<curl/curl.h>
/* The MinGW headers are missing a few Win32 function definitions,
you shouldn't need this if you use VC++ */
int
__cdecl
_snscanf
(
const
char
*
input
,
size_t
length
,
const
char
*
format
,
...);
/* parse headers for Content-Length */
size_t
getcontentlengthfunc
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
{
int
r
;
long
len
=
0
;
/* _snscanf() is Win32 specific */
r
=
_snscanf
(
ptr
,
size
*
nmemb
,
"Content-Length: %ld
\n
"
,
&
len
);
if
(
r
)
/* Microsoft: we don't read the specs */
*
((
long
*
)
stream
)
=
len
;
return
size
*
nmemb
;
}
/* discard downloaded data */
size_t
discardfunc
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
{
return
size
*
nmemb
;
}
/* read data to upload */
size_t
readfunc
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
{
FILE
*
f
=
stream
;
size_t
n
;
if
(
ferror
(
f
))
return
CURL_READFUNC_ABORT
;
n
=
fread
(
ptr
,
size
,
nmemb
,
f
)
*
size
;
return
n
;
}
int
upload
(
CURL
*
curlhandle
,
const
char
*
remotepath
,
const
char
*
localpath
,
long
timeout
,
long
tries
)
{
FILE
*
f
;
long
uploaded_len
=
0
;
CURLcode
r
=
CURLE_GOT_NOTHING
;
int
c
;
f
=
fopen
(
localpath
,
"rb"
);
if
(
f
==
NULL
)
{
perror
(
NULL
);
return
0
;
}
curl_easy_setopt
(
curlhandle
,
CURLOPT_UPLOAD
,
TRUE
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_URL
,
remotepath
);
if
(
timeout
)
curl_easy_setopt
(
curlhandle
,
CURLOPT_FTP_RESPONSE_TIMEOUT
,
timeout
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_HEADERFUNCTION
,
getcontentlengthfunc
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_HEADERDATA
,
&
uploaded_len
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_WRITEFUNCTION
,
discardfunc
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_READFUNCTION
,
readfunc
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_READDATA
,
f
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_FTPPORT
,
"-"
);
/* disable passive mode */
curl_easy_setopt
(
curlhandle
,
CURLOPT_FTP_CREATE_MISSING_DIRS
,
TRUE
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_VERBOSE
,
TRUE
);
for
(
c
=
0
;
(
r
!=
CURLE_OK
)
&&
(
c
<
tries
);
c
++
)
{
/* are we resuming? */
if
(
c
)
{
/* yes */
/* determine the length of the file already written */
/*
* With NOBODY and NOHEADER, libcurl will issue a SIZE
* command, but the only way to retrieve the result is
* to parse the returned Content-Length header. Thus,
* getcontentlengthfunc(). We need discardfunc() above
* because HEADER will dump the headers to stdout
* without it.
*/
curl_easy_setopt
(
curlhandle
,
CURLOPT_NOBODY
,
TRUE
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_HEADER
,
TRUE
);
r
=
curl_easy_perform
(
curlhandle
);
if
(
r
!=
CURLE_OK
)
continue
;
curl_easy_setopt
(
curlhandle
,
CURLOPT_NOBODY
,
FALSE
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_HEADER
,
FALSE
);
fseek
(
f
,
uploaded_len
,
SEEK_SET
);
curl_easy_setopt
(
curlhandle
,
CURLOPT_FTPAPPEND
,
TRUE
);
}
else
{
/* no */
curl_easy_setopt
(
curlhandle
,
CURLOPT_FTPAPPEND
,
FALSE
);
}
r
=
curl_easy_perform
(
curlhandle
);
}
fclose
(
f
);
if
(
r
==
CURLE_OK
)
return
1
;
else
{
fprintf
(
stderr
,
"%s
\n
"
,
curl_easy_strerror
(
r
));
return
0
;
}
}
int
main
(
int
c
,
char
**
argv
)
{
CURL
*
curlhandle
=
NULL
;
curl_global_init
(
CURL_GLOBAL_ALL
);
curlhandle
=
curl_easy_init
();
upload
(
curlhandle
,
"ftp://user:pass@host/path/file"
,
"C:
\\
file"
,
0
,
3
);
curl_easy_cleanup
(
curlhandle
);
curl_global_cleanup
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment