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 :(

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... :(

Edited 5 Years Ago by SpecialForce: n/a

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

Edited 5 Years Ago by SpecialForce: n/a

This question has already been answered. Start a new discussion instead.