Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I have written an application that transfers files using FTP. I now need to change this program since some of my clients no longer allow FTP applications and are requesting that I use HTTP/HTTPS instead. Does anyone know of any commercial libraries/SDK that I could use to achieve this? I should note that my application is written in C++ and is complied with VS 2008 and it is not a .NET application.

Any help (including possible sample code on how to achieve file transfer using HTTPS) would be greatly appreciated.

Thank you,
A.
Posted

Im afraid the post of mine is not commercial:

HRESULT  iStreamHttp::WriteStream(const TCHAR* url,IStream* stream)
{
  CloseURL();

  _hiOpen = InternetOpen(UserAgent(),INTERNET_OPEN_TYPE_PRECONFIG,0,0,0);
  if(!_hiOpen) return E_FAIL;

  long    timeout = DEF_TIMEOUT;
  long    context = (long)this;

  InternetSetOption(_hiOpen,INTERNET_OPTION_CONNECT_TIMEOUT,&timeout,sizeof(timeout));
  InternetSetOption(_hiOpen,INTERNET_OPTION_RECEIVE_TIMEOUT,&timeout,sizeof(timeout));

  tArr<TCHAR>    domain;
  tArr<TCHAR>    path;

  SplitURL(url,domain,path);
  _hiConnect = InternetConnect(_hiOpen,domain.array,INTERNET_DEFAULT_HTTP_PORT,0,0,INTERNET_SERVICE_HTTP,0,context);
  if(!_hiConnect) return E_FAIL;

  unsigned long  dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;

  _hiUrl = HttpOpenRequest(_hiConnect,__TEXT("POST"),path.array,0,0,0,dwFlags,context);
  if(!_hiUrl) return E_FAIL;

  INTERNET_BUFFERS  buffer;
  ULARGE_INTEGER    size = {0,0};
  LARGE_INTEGER      null = {0,0};
  ULARGE_INTEGER    seek = {0,0};
  TCHAR              status[256];
  unsigned long      cb;

  if(S_OK==stream->Seek(null,SEEK_END,&seek))
  {
    memset(&buffer,0,sizeof(buffer));

    buffer.dwStructSize  = sizeof(buffer);
    buffer.dwBufferTotal = seek.LowPart;

    if(HttpSendRequestEx(_hiUrl,&buffer,0,0,context))
    {
      char          buff[0x1000];
      unsigned long  read;
      unsigned long  writ;

      stream->Seek(null,SEEK_SET,&seek);
      while((S_OK==stream->Read(buff,sizeof(buff),&read)) && (0<read))
      {
        InternetWriteFile(_hiUrl,buff,read,&writ);
      }

      cb = sizeof(status)/sizeof(status[0]);
      if(HttpQueryInfo(_hiUrl,HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,status,&cb,0))
        _dwStatus = *(int*)status;
      else if(HttpQueryInfo(_hiUrl,HTTP_QUERY_STATUS_CODE,status,&cb,0))
        _dwStatus = _wtoi(status);
      else
        _dwStatus = 0;

      HttpEndRequest(_hiUrl,&buffer,0,0);
    }
  }

  // CloseURL();
  return S_OK;
}


enum
{
  URL_CHAR,
  URL_ENCODE,
  URL_SLASH,
  URL_PARAM,
  URL_ANCHOR,
};

const int  __isurl(const TCHAR cc)
{
  switch(cc)
  {
    case '/': return URL_SLASH;
    case '?': return URL_PARAM;
    case '#': return URL_ANCHOR;

  }
  return URL_CHAR;
}

unsigned int iStreamHttp::SplitURL(const TCHAR* url,tArr<TCHAR>& domain,tArr<TCHAR>& path)
{
  unsigned int  anf,end;
  unsigned int  anfd,endd;

  for(anf=0;url[anf] && ('/'!=url[anf]);anf++);
  for(     ;url[anf] && ('/'==url[anf]);anf++);
  if(url[end=anf]) for(;url[end] && ('/'!=url[end]);end++);

  anfd = anf; endd = end;
  for(anf=end;url[end] && (URL_ANCHOR!=__isurl(url[end]));end++);
  scopy(path,0,url+anf,end-anf);
  
  return scopy(domain,0,url+anfd,endd-anfd);
}

Good luck.
 
Share this answer
 
http://curl.haxx.se/libcurl/
Just for an example this is their trial code for how you download https


<pre lang="cs">/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ &lt;| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2011, Daniel Stenberg, &lt;daniel@haxx.se&gt;, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at http://curl.haxx.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
#include &lt;stdio.h&gt;
#include &lt;curl/curl.h&gt;
int main(void)
{
  CURL *curl;
  CURLcode res;
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
#ifdef SKIP_PEER_VERIFICATION
    /*
     * If you want to connect to a site who isn't using a certificate that is
     * signed by one of the certs in the CA bundle you have, you can skip the
     * verification of the server's certificate. This makes the connection
     * A LOT LESS SECURE.
     *
     * If you have a CA cert for the server stored someplace else than in the
     * default bundle, then the CURLOPT_CAPATH option might come handy for
     * you.
     */
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif
#ifdef SKIP_HOSTNAME_VERFICATION
    /*
     * If the site you're connecting to uses a different host name that what
     * they have mentioned in their server certificate's commonName (or
     * subjectAltName) fields, libcurl will refuse to connect. You can skip
     * this check, but this will make the connection less secure.
     */
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif
    res = curl_easy_perform(curl);
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900