从FTP切换到HTTPS [英] Switching from FTP to HTTPS

查看:200
本文介绍了从FTP切换到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我编写了一个使用FTP传输文件的应用程序.现在,我需要更改此程序,因为某些客户端不再允许FTP应用程序,而是要求我改用HTTP/HTTPS.有谁知道我可以用来实现这一目标的任何商业库/SDK?我应该注意,我的应用程序是用C ++编写的,并且已与VS 2008兼容,它不是.NET应用程序.

任何帮助(包括有关如何使用HTTPS实现文件传输的示例代码)将不胜感激.

谢谢
A.

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.

推荐答案

恐怕我的帖子不具有商业意义:

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.


http://curl.haxx.se/libcurl/
仅举一个例子,这是他们如何下载https
的试用代码.

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;
}



这篇关于从FTP切换到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆