CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2006
    Posts
    3

    https upload file

    Hi everyone,

    I should start out by saying, I do not know ANY C++, I have to modifiy someone else's code, to upload a file over https to a php script on the webserver.
    This works now by using FTP. I have the code that does this below
    Code:
    int UploadFile(const char *serverName, const char* localFile, const char* remoteFile)
    {
    	int error = 0;
    	CFtpConnection *ftp = NULL;
    	BOOL ok;
    
    	try {
    		CInternetSession session(_T("Upload/1.0"));
    
    		ftp = session.GetFtpConnection(serverName, "user", "pass");
    		ok = ftp->SetCurrentDirectory(_T("data"));
    		if (ok) {
    			ok = ftp->PutFile(localFile, remoteFile, FTP_TRANSFER_TYPE_ASCII);
    		}
    
    		if (!ok) {
    			error = GetLastError();
    		}
    	}
    	catch (CInternetException* exc) {
    		error = GetLastError();
    	}
    
    	// if the connection is open, close it
    	if (ftp != NULL) {
    		ftp->Close();
    	}
    	delete ftp;
    
    	return error;
    }
    So my question, is can someone write in a drop in replacement code for this. You can hardcode the URL in the code. I am using vb.net C++.

    As I really don't know what I am doing, I am willing to pay for someone to do this, let me know and we can work out a price.

    Thank you,
    Mike
    Last edited by mlh; April 27th, 2006 at 02:37 PM.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: https upload file


  3. #3
    Join Date
    Apr 2006
    Posts
    3

    Re: https upload file

    I was hoping that there would be a small amount of code someone could point me to and use. I do know perl and php. If there is a well documented class that does this, I could figure it out. I will also post the request in the places you have offered.

    Thank you,
    Mike

  4. #4
    Join Date
    Apr 1999
    Posts
    3,585

    Re: https upload file

    You may find WinInetPost helpful.
    Gort...Klaatu, Barada Nikto!

  5. #5
    Join Date
    May 2009
    Posts
    140

    Re: https upload file

    Quote Originally Posted by mlh View Post
    Hi everyone,

    I should start out by saying, I do not know ANY C++, I have to modifiy someone else's code, to upload a file over https to a php script on the webserver.
    This works now by using FTP. I have the code that does this below
    Code:
    int UploadFile(const char *serverName, const char* localFile, const char* remoteFile)
    {
    	int error = 0;
    	CFtpConnection *ftp = NULL;
    	BOOL ok;
    
    	try {
    		CInternetSession session(_T("Upload/1.0"));
    
    		ftp = session.GetFtpConnection(serverName, "user", "pass");
    		ok = ftp->SetCurrentDirectory(_T("data"));
    		if (ok) {
    			ok = ftp->PutFile(localFile, remoteFile, FTP_TRANSFER_TYPE_ASCII);
    		}
    
    		if (!ok) {
    			error = GetLastError();
    		}
    	}
    	catch (CInternetException* exc) {
    		error = GetLastError();
    	}
    
    	// if the connection is open, close it
    	if (ftp != NULL) {
    		ftp->Close();
    	}
    	delete ftp;
    
    	return error;
    }
    So my question, is can someone write in a drop in replacement code for this. You can hardcode the URL in the code. I am using vb.net C++.

    As I really don't know what I am doing, I am willing to pay for someone to do this, let me know and we can work out a price.

    Thank you,
    Mike
    sorry i'm new to C++ but what do i include to make this code work?

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: https upload file

    Uploading a file via https is considerably more complex than uploading over FTP.

    Remember that HTTP was primarily developped as a RECEIVE-only type query. Posting data takes a bit of work.

    You will need to read the file, convert the binary data to 7bit ascii so it can be posted. This will require you to create a routine to use one of the binary-to-ascii converscion schemes supported by your web server. The most common one being 'application/octet-stream'.

    The FTP code is a few lines. Expect a https upload solution to be several dozen lines to maybe a couple hundred lines of code... Mainly to turn the file you want to upload into the proper HTTP post-compatible format.

  7. #7
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    Re: https upload file

    On linux C++ this is easily done with openssl.
    The windows openssl could do it too but the current version moronically pauses a second between each step.
    e.g.

    openssl s_client -host adwords.google.com -port 443
    POST /api/adwords/v13/AdGroupService HTTP/1.0
    Host: adwords.google.com
    SOAPAction: ""
    Content-Length: 952

    YOUR CONTENT OF 952 bytes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured