Hello, I am trying to upload a file via ftp using the library curl. Of course I looked here but the exemples don't say how to do this using usarname and password. Aslo the code is in C and if I compile it in C++ I am getting:

error C2664: 'fread' : cannot convert parameter 4 from 'void *' to 'FILE *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

Could you guys please help me to find out how can I upload a file to a ftp server?

P.S. Sorry for my bad english :(

Recommended Answers

All 4 Replies

don't say how to do this using usarname and password.

One way is to put the username and password in the URL ftp://username:password@hostname/
see: RFC 1738 http://www.ietf.org/rfc/rfc1738.txt
In the example cited:

//#define REMOTE_URL      "ftp://example.com/"  UPLOAD_FILE_AS
#define REMOTE_URL      "ftp://username:password@example.com/"  UPLOAD_FILE_AS

Passing the username and password in plaintext is usually inadvisable; cyphertext should be used instead.
To find out how to do this, see: RFC 2228 http://www.ietf.org/rfc/rfc2228.txt

error C2664: 'fread' : cannot convert parameter 4 from 'void *' to 'FILE *'

Cast the expression to a FILE*.

// size_t retcode = fread(ptr, size, nmemb, stream);
std::size_t retcode = std::fread( ptr, size, nmemb, static_cast<std::FILE*>(stream) ) ;

You might want to use a C++ wrapper for libcurl. http://www.curlpp.org/

Thanks a lot, vijayan121. Now I made it work in c++ using username and password! Sadly I notice another problem: when I compile it on debug evrything is OK, but on release I am getting:

LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

and after about a second of run time the program crashes... :(

The libcurl libray you are linking to is using a different version of the C Runtime Library. In your project, modify the settings to use the DLL version of the CRT. For the debug build, link to the debug build of libcurl; for the release link to the release build of libcurl.
See: http://msdn.microsoft.com/en-us/library/6wtdswk0%28v=VS.100%29.aspx

Thanks a lot for your help, vijayan121! I found the solution on the link you provide.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.