How to login a website and download/upload files

Basicly I want to make a c++ program which does the following:

1- logs in to 4shared.com with username 'user_example' and password 'password_example'.
2- uploads to the 4shared account a file named 'test_upload.txt' located in 'C:\test\'
3- downloads a file named 'test_download.txt' from the 4sared account

I user curl 7.39.0 and curlpp 0.7.3

I don't expect someone to give me a full answer but help me out with some difficulties:

1- how to keep the same session between successive http requests
2- how to make an http request to upload a file
3- how to get the url of a file with specified name on a 4shared account

Any help would be appreciated
Last edited on
Unless if you have created a internet browser, just give up right now.
It looks like 4shared.com supports WebDAV: http://www.4shared.com/faq.jsp#q36 which should be possible to do with libcURL. Unfortunatly they do not list a WebDAV example in their Example Sources section. If you are premium then the FAQ I linked to above says that you can use FTP which does have an example listed at libcURL:

- Upload http://curl.haxx.se/libcurl/c/ftpupload.html

- Download http://curl.haxx.se/libcurl/c/ftpget.html

I haven't tried any of this, but it doesn't look too hard at a first glance.
I get the following error code:

1
2
3
undefined reference to `_imp__curl_global_init'
undefined reference to `_imp__curl_easy_init'
//and more and more ... 


Here's the command I use:

mingw32-g++.exe -o Debug\PC_Control.exe Debug\Main.o "C:\Program Files (x86)\CodeBlocks\MinGW\lib\libcomdlg32.a"

The content of Main.cpp is exactly the same as the content of ftpupload.c but 1 change: I replaces "FILE *stream" with "void *stream" because of another error I received.
Why are you using the command line? For that matter what are you trying to do with libcomdlg32.a? You have to link to libcurl. Undo that change you made to "FILE *stream" and tell us what error you originally got.
How can I link to libcurl? I forgot how I did it for libcomdlg32.a
I have just copied "curl\include" from download pack to "\Program Files (x86)\CodeBlocks\MinGW\"
I have just copied "curl\include" from download pack to "\Program Files (x86)\CodeBlocks\MinGW\"

So wait, you didn't build it yet? You should do that first. After all you can't link to something that isn't there, right?
Please can you explain what should I do exacrly, how to "build it" and how to link
Since you're using MingW, step one is to launch MSYS. If you do not have MSYS, then you have to download it: http://www.mingw.org/wiki/MSYS

After that, you will have a batch file in what ever directory you installed MSYS to called "msys.bat", run this with administrative privileges. This will open what appears to be a *nix like terminal window. from there use the 'cd' command to change the working directory to the folder where you unzipped cURL to (you may want to redownload cURL for this in case you cut and pasted from your last attempt). Remember to switch out the '\' characters in the normal windows directory with '/' characters. After that, you enter './configure' into the command line and wait a while until in finishes. As the name suggests, this will configure the makefile for you, this takes a while, as in it may be time to run out for coffee or go make yourself a sandwich kind of time pretty much regardless of how powerful your computer is. Get to this point and post back if you have any trouble.
Last edited on
It compiles fine but when I run the program it sais that the program can't start because libcurl.dll is missing from my computer. I don't want my program to use DLL files, I want to use static linking. I found some informations on how do I statically link libcurl:

5.7 in the FAQ says:

When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.

How can I add "-DCURL_STATICLIB" parameter to CFLAGS in Code::Blocks?
I have already added "-DCURL_STATICLIB" to compiler options AND linker options. Also, I have defined CURL_STATICLIB in my script before including curl/curl.h. I don't know what libraries to import, I tried many of them I've downloaded, I tried libcurl.lib, all of the .a and the .dll.a files. This thing makes me crazy, I don't know what to do, all forums are full of posts that don't work.






Also, I don't know how should I define REMOTE_URL in order to upload the file 'C:\test\test_upload.txt' to the 4shared.com account with username 'user_example' and password 'password_example':

1
2
3
4
#define LOCAL_FILE      "/tmp/uploadthis.txt"
#define UPLOAD_FILE_AS  "while-uploading.txt"
#define REMOTE_URL      "ftp://example.com/"  UPLOAD_FILE_AS
#define RENAME_FILE_TO  "renamed-and-fine.txt" 


Thanks in advance.
Last edited on
There will be two versions of the "libcurl.a" file, one that is intended for statically linking and one that is meant for dynamic linking. So make sure you are linking to the correct file in that regard. If you are getting that error then it sounds like you are linking to the dynamic version of the file.
How should I define REMOTE_URL in order to upload the file 'C:\test\test_upload.txt' to the 4shared.com account with username 'user_example' and password 'password_example'?

1
2
3
4
#define LOCAL_FILE      "/tmp/uploadthis.txt"
#define UPLOAD_FILE_AS  "while-uploading.txt"
#define REMOTE_URL      "ftp://example.com/"  UPLOAD_FILE_AS
#define RENAME_FILE_TO  "renamed-and-fine.txt"  


Link you posted: http://curl.haxx.se/libcurl/c/ftpupload.html

Also, I found another link which does not use FTP so I think it may work better. Same question: how should I define constants?
http://curl.haxx.se/libcurl/c/fileupload.html
Last edited on
It looks like the target URL should be ftp.4shared.com : http://www.4shared.com/faq.jsp#q37

Again, it looks like you need a "premium account" for this to work. At least according to the FAQ from that site.

That second bit of code looks like it is judt using an HTTP PUT command to push the file: http://curl.haxx.se/libcurl/c/CURLOPT_UPLOAD.html . That won't work here.
I'll use FileZilla, thanks anyway.
I'll use FileZilla, thanks anyway.

... This was a functional request!?!? I don't even know what to say here.
If I can connect to domain specified with the informations below using FileZilla, how can I do it using a C++ program to upload a file to it?

Host: x.example.com
Username: user_example
Password: pass_example
Port: 99

How should I edit this file? where should I enter the host/user/pass/port informations in my code? http://curl.haxx.se/libcurl/c/ftpupload.html
Last edited on
Topic archived. No new replies allowed.