当前位置: 首页 > news >正文

企业制作网站公司/公司网站制作模板

企业制作网站公司,公司网站制作模板,深圳 做公司网站,做一公司网站1. 通过 GetFile 方式下载2. 通过 CInternetFile::Read 方式下载两种方式的区别:第一种方式,操作级别较高。直接调用就好,这种方式封装了一切操作。第二种方式,自己可以控制。其基本原理,就是在网络上打开一个文件&…

1. 通过 GetFile 方式下载
2. 通过 CInternetFile::Read 方式下载

两种方式的区别:
第一种方式,操作级别较高。直接调用就好,这种方式封装了一切操作。
第二种方式,自己可以控制。其基本原理,就是在网络上打开一个文件,就像本地打开文件一样。读取,然后写入到本地文件。

以下代码,两种方式都有,第二种方式注释掉了。打开即可使用。

在FTP下载中,碰到的奇异问题:
下载大于100M的文件。
今天,下载到最后一块,出现timeout。
在本地建立ftp良好。
在其他测试环境良好。
下一步,在另外一个计算机上建立ftp再测试下。确定是ftp服务器问题,还是客户端问题。
另外出问题的时候,用filezilla客户端下载,良好。

找到一个 FTP Client 类。使用后,再议。
http://www.codeproject.com/KB/IP/ftpclientclass.aspx

服务器端使用filezilla 。

5.15问题已解决,和信令无关。

bool DownloadFile(char *filename)
{
 CInternetSession* pInetSession; //会话对象
 CFtpConnection* pFtpConnection; //连接对象
 
 pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
 
 try
 {
  //新建连接对象
  pFtpConnection=pInetSession->GetFtpConnection("127.0.0.1", "sa", "111");
 }
 catch(CInternetException *pEx)
 {
  //获取错误
  TCHAR szError[1024];
  if(pEx->GetErrorMessage(szError,1024))
   AfxMessageBox(szError);
  else 
   AfxMessageBox("There was an exception");
  pEx->Delete();
  
  return FALSE;
 }
 
 TCHAR tchBuffer[MAX_PATH];
 GetCurrentDirectory(MAX_PATH, tchBuffer);
 strcat(tchBuffer, filename + 1);
 
 
 if(pFtpConnection->GetFile(filename, "d:\\2.exe", false))
 {
  //AfxMessageBox("下载成功");
 }
 else
  DWORD dResult = GetLastError();

/* 
 CInternetFile *pInternetFile = pFtpConnection->OpenFile(filename, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 1);
 char szBuffer[4096];

 CFile file("d:\\1.exe", CFile::modeWrite | CFile::modeCreate | CFile::typeBinary);
 UINT uRead;

 int count = 0;
 
 while (true)
 {
  try
  {
   uRead = pInternetFile->Read(szBuffer, 4096);
   ++count;
   TRACE2("%d %d\n", count, uRead);

  }
  catch (CInternetException *pEx)
  {
   //获取错误
   TCHAR szError[1024];
   if(pEx->GetErrorMessage(szError,1024))
    AfxMessageBox(szError);
   else 
    AfxMessageBox("There was an exception");
   
   pEx->Delete();
  }
  
  file.Write(szBuffer, uRead);

  if ( uRead < 4096 )
   break;
  
 }

 file.Close();
 pInternetFile->Close();
 delete pInternetFile; */

 if ( NULL != pFtpConnection )
  pFtpConnection->Close();
 delete pFtpConnection;
 delete pInetSession;

 return true;

}

第二种方式下载的函数
CString GetFTPFile(const char *ftpserver, const char *remotefile,
                      const char *localfile )
{
    TCHAR   szCause[255];
    CString sCause;
    sCause.Format(""); 
 
    try
    {
  TCHAR ftpAgent[256] = _T("FTPSource");
        //create the internet session

        CInternetSession mysession(ftpAgent,
   1,
   INTERNET_OPEN_TYPE_PRECONFIG,
   NULL,
   NULL,
     INTERNET_FLAG_DONT_CACHE);

        //get the ftp connection from internet session
        CFtpConnection* pFtpConn = mysession.GetFtpConnection(ftpserver,"sa","111");
       
        if(pFtpConn)
        {
   CFtpFileFind finder(pFtpConn);
   finder.FindFile(remotefile);
   finder.FindNextFile();
   
   FILE* fp = fopen(localfile,"wb");
   if(fp == NULL)
   {
    return "file open error";
   }
   __int64  _fileSize = finder.GetLength64();
   
   CInternetFile* _pFtpFile = pFtpConn->OpenFile(remotefile,
    GENERIC_READ,
    FTP_TRANSFER_TYPE_BINARY|INTERNET_FLAG_DONT_CACHE,
    1);
   
   _pFtpFile->SetReadBufferSize(READSIZE);
   int i = 1;
            while(_fileSize > 0 )
   {
    char temp[READSIZE]= "\0";
    if(_fileSize > READSIZE)
    {
     
     _pFtpFile->Read((LPVOID)temp, READSIZE );     
     _fileSize = _fileSize - READSIZE;
     
     fwrite(temp,READSIZE,1,fp);
    }
    else
    {
     _pFtpFile->Read((LPVOID)temp, _fileSize );  
     fwrite(temp,sizeof(char),_fileSize,fp);
     _fileSize = 0;
    }
   }
   _pFtpFile->Close();
   fclose(fp);
        }
        else
        {
   //could not connect
   sCause.Format("Could not connect to ftp server!! \nPlease "
    "ensure you have correct address and access rights!");
        }     
    }
 
    catch(CException* error)
    {
        error->GetErrorMessage(szCause,254,NULL);
        sCause.Format("%s",szCause);
    }

    return (sCause);
}

http://www.jmfq.cn/news/5013487.html

相关文章:

  • 做网站导航cms/如何推广seo
  • 响应式网站和展示式区别/sem是什么仪器
  • 网站微信推广方案/网站查询域名ip
  • 调研报告 政府网站建设/国内产女装一线二线品牌知乎
  • 中远智达网站建设/网站优化分析
  • 网站公司怎么做的好/推广软件的app
  • 台州网站建设费用/上海搜索引擎优化1
  • 深圳网站设计制作建设/seo实战培训课程
  • 新乡网站制作/网站页面关键词优化
  • 司机找事做那个网站靠谱/计算机培训机构排名前十
  • 重庆网站平台/北京网站建设东轩seo
  • 怎么创建网站相册/seo点击排名工具有用吗
  • 禹州做网站的公司/seo如何提升排名收录
  • 北京所有公司名单/seo外包公司需要什么
  • 怎么做能收费的视频网站/宁波关键词优化时间
  • 怎么查网站是哪家制作公司做的/百度客户管理系统登录
  • 连云港网站制作/seo快速排名培训
  • 怎么做网站链接支付/seo实战培训中心
  • 全国今日生猪价格涨跌表价格/厦门最快seo
  • wplounge wordpress主题/优化seo哪家好
  • WordPress网站加载时间/360站长
  • 室内设计效果图背景墙/百度官方优化指南
  • 中国自适应网站建设/360站长工具
  • 百年建筑网/公众号seo排名优化
  • 苏州网站建站/免费推广工具
  • 常德市政府门户网站群建设方案/买友情链接有用吗
  • 做一个简单的管理系统/网站seo优化报告
  • 外贸网站建设及优化ppt模块/一个产品的网络营销方案
  • 绵阳微信网站/如何做网站
  • 网站推广规范/友情链接图片