四、下载
(只是处理二级目录)
global type f_connect_ftpcopyfile from function_object
end type

forward prototypes
global function integer f_connect_ftpcopyfile (hprogressbar hpb_1, long al_copycount)
end prototypes

global function integer f_connect_ftpcopyfile (hprogressbar hpb_1, long al_copycount);
do while yield()
loop

string ls_directorya1 //远程目录
string ls_directorya2 //本地目录
string ls_filename,ls_file

//本地目录
ls_directorya2 = gs_application_path

string ls_directoryb1 //远程目录
string ls_directoryb2 //本地目录

string ls_filename1 //远程文件
string ls_filename2 //本地文件

long ll_hret
long ll_hftp1
long ll_hftp2
long ll_fftp1
long ll_fftp2
long ll_m
long ll_filehandle1,ll_filehandle2

integer li_ret

boolean lb_success
boolean lb_find

s_WIN32_FIND_DATA ss_file1,ss_file2

w_autodown_test.st_ts.text = '正在检查需要更新软件的数量...'
li_ret = f_connect_ftpserver()
if li_ret = -1 then return -1
w_autodown_test.st_ts.text = '正在更新软件版本...'
//建立连接
ll_hret = InternetOpenA(gs_application_name,0,'','',0)
choose case li_ret
 case 1
  ls_directorya1 = GS_FTPDIR1
  ll_hftp1 = InternetConnectA(ll_hret,GS_FTPSERVER1,GL_FTPLOGINPORT1,GS_FTPLOGINUSER1,GS_FTPLOGINPASS1,1,0,0)
 case 2
  ls_directorya1 = GS_FTPDIR2
  ll_hftp1 = InternetConnectA(ll_hret,GS_FTPSERVER2,GL_FTPLOGINPORT2,GS_FTPLOGINUSER2,GS_FTPLOGINPASS2,1,0,0)
 case 3
  ls_directorya1 = GS_FTPDIR3
  ll_hftp1 = InternetConnectA(ll_hret,GS_FTPSERVER3,GL_FTPLOGINPORT3,GS_FTPLOGINUSER3,GS_FTPLOGINPASS3,1,0,0)
 case else
  InternetCloseHandle(ll_hret);
  return -1
end choose
//进入FTP目录
lb_success = FtpSetCurrentDirectoryA(ll_hftp1,ls_directorya1)
if not lb_success then
 InternetCloseHandle(ll_hret);
 InternetCloseHandle(ll_hftp1);
 return -1
end IF
//获取第一个文件
ll_fftp1 = FtpFindFirstFileA(ll_hftp1,'',ss_file1,0,0)
if ll_fftp1 = 0 then
 InternetCloseHandle(ll_hret);
 InternetCloseHandle(ll_hftp1);
 InternetCloseHandle(ll_fftp1);
 return 0
end if
//初始化提示栏
hpb_1.position = 0
ll_m = 0
//是目录
if ss_file1.dwFileAttributes = 16 then
 //远程目录
 ls_directoryb1 = ls_directorya1 + '/' + ss_file1.cfilename
 //本地目录
 ls_directoryb2 = ls_directorya2 + '/' + ss_file1.cfilename
 //本地目录不存在的创建目录
 if directoryexists(ls_directoryb2) = false then
  CreateDirectory(ls_directoryb2)
  ll_m++
  hpb_1.position = ll_m / al_copycount * 100
 end if
 //创建第二个目录句柄
 choose case li_ret
  case 1
   ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER1,GL_FTPLOGINPORT1,GS_FTPLOGINUSER1,GS_FTPLOGINPASS1,1,0,0)
  case 2
   ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER2,GL_FTPLOGINPORT2,GS_FTPLOGINUSER2,GS_FTPLOGINPASS2,1,0,0)
  case 3
   ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER3,GL_FTPLOGINPORT3,GS_FTPLOGINUSER3,GS_FTPLOGINPASS3,1,0,0)
 end choose
 //转移到第二级目录
 lb_success = FtpSetCurrentDirectoryA(ll_hftp2,ls_directoryb1)
 if lb_success  then
  //浏览目录内容
  ll_fftp2 = FtpFindFirstFileA(ll_hftp2,'',ss_file1,0,0)
  //本地文件
  ls_filename2 = ls_directoryb2 + '/' + ss_file1.cfilename
  if fileexists(ls_filename2) = false then
   //本地文件不存在的,直接获取
   FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
   ll_m++
   hpb_1.position = ll_m / al_copycount * 100
  else //本地文件存在的,比较文件时间
   ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
   FindClose(ll_filehandle2)
   choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
    case 0
     //两个时间相等,就返回零
    case 1
     //如lpFileTime2小于lpFileTime1,返回1
     //下载
     FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
     ll_m++
     hpb_1.position = ll_m / al_copycount * 100
    case -1
     //如lpFileTime1小于lpFileTime2,返回-1
   end choose
  end if
  //遍历目录
  do while InternetFindnextFileA(ll_fftp2, ss_file1)
   yield()
   //本地文件
   ls_filename2 = ls_directoryb2 + '/' + ss_file1.cfilename
   if fileexists(ls_filename2) = false then
    //本地文件不存在的,直接获取
    FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
    ll_m++
    hpb_1.position = ll_m / al_copycount * 100
   else //本地文件存在的,比较文件时间
    ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
    FindClose(ll_filehandle2)
    choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
     case 0
      //两个时间相等,就返回零
     case 1
      //如lpFileTime2小于lpFileTime1,返回1
      //下载
      FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
      ll_m++
      hpb_1.position = ll_m / al_copycount * 100
     case -1
      //如lpFileTime1小于lpFileTime2,返回-1
    end choose
   end if
  loop
  InternetCloseHandle(ll_hftp2);
  InternetCloseHandle(ll_fftp2);
 end if
else //是文件
 //本地文件
 ls_filename2 = ls_directorya2 + '/' + ss_file1.cfilename
 if fileexists(ls_filename2) = false then
  //本地文件不存在的,直接获取
  lb_find = FtpGetFileA(ll_hftp1,ss_file1.cfilename,ls_filename2,false,0,0,0)
  ll_m++
  hpb_1.position = ll_m / al_copycount * 100
 else //本地文件存在的,比较文件时间
  ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
  FindClose(ll_filehandle2)
  choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
   case 0
    //两个时间相等,就返回零
   case 1
    //如lpFileTime2小于lpFileTime1,返回1
    //下载
    lb_find = FtpGetFileA(ll_hftp1,ss_file1.cfilename,ls_filename2,false,0,0,0)
    ll_m++
    hpb_1.position = ll_m / al_copycount * 100
   case -1
    //如lpFileTime1小于lpFileTime2,返回-1
  end choose
 end if
end if
//遍历目录
do while InternetFindnextFileA(ll_fftp1, ss_file1)
 yield()
 //是目录
 if ss_file1.dwFileAttributes = 16 then
  //远程目录
  ls_directoryb1 = ls_directorya1 + '/' + ss_file1.cfilename
  //本地目录
  ls_directoryb2 = ls_directorya2 + '/' + ss_file1.cfilename
  //本地目录不存在的创建目录
  if directoryexists(ls_directoryb2) = false then
   CreateDirectory(ls_directoryb2)
   ll_m++
   hpb_1.position = ll_m / al_copycount * 100
  end if
  //创建第二个目录句柄
  choose case li_ret
   case 1
    ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER1,GL_FTPLOGINPORT1,GS_FTPLOGINUSER1,GS_FTPLOGINPASS1,1,0,0)
   case 2
    ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER2,GL_FTPLOGINPORT2,GS_FTPLOGINUSER2,GS_FTPLOGINPASS2,1,0,0)
   case 3
    ll_hftp2 = InternetConnectA(ll_hret,GS_FTPSERVER3,GL_FTPLOGINPORT3,GS_FTPLOGINUSER3,GS_FTPLOGINPASS3,1,0,0)
  end choose
  //转移到第二级目录
  lb_success = FtpSetCurrentDirectoryA(ll_hftp2,ls_directoryb1)
  if lb_success then
   //浏览目录内容
   ll_fftp2 = FtpFindFirstFileA(ll_hftp2,'',ss_file1,0,0)
   //本地文件
   ls_filename2 = ls_directoryb2 + '/' + ss_file1.cfilename
   if fileexists(ls_filename2) = false then
    //本地文件不存在的,直接获取
    lb_find = FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
    ll_m++
    hpb_1.position = ll_m / al_copycount * 100
   else //本地文件存在的,比较文件时间
    ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
    FindClose(ll_filehandle2)
    choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
     case 0
      //两个时间相等,就返回零
     case 1
      //如lpFileTime2小于lpFileTime1,返回1
      //下载
      lb_find = FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
      ll_m++
      hpb_1.position = ll_m / al_copycount * 100
     case -1
      //如lpFileTime1小于lpFileTime2,返回-1
    end choose
   end if
   //遍历目录
   do while InternetFindnextFileA(ll_fftp2, ss_file1)
    yield()
    //本地文件
    ls_filename2 = ls_directoryb2 + '/' + ss_file1.cfilename
    if fileexists(ls_filename2) = false then
     //本地文件不存在的,直接获取
     lb_find = FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
     ll_m++
     hpb_1.position = ll_m / al_copycount * 100
    else //本地文件存在的,比较文件时间
     ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
     FindClose(ll_filehandle2)
     choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
      case 0
       //两个时间相等,就返回零
      case 1
       //如lpFileTime2小于lpFileTime1,返回1
       //下载
       lb_find = FtpGetFileA(ll_hftp2,ss_file1.cfilename,ls_filename2,false,0,0,0)
       ll_m++
       hpb_1.position = ll_m / al_copycount * 100
      case -1
       //如lpFileTime1小于lpFileTime2,返回-1
     end choose
    end if
   loop
   InternetCloseHandle(ll_hftp2);
   InternetCloseHandle(ll_fftp2);
  end if
 else //是文件
  //本地文件
  ls_filename2 = ls_directorya2 + '/' + ss_file1.cfilename
  if fileexists(ls_filename2) = false then
   //本地文件不存在的,直接获取
   lb_find = FtpGetFileA(ll_hftp1,ss_file1.cfilename,ls_filename2,false,0,0,0)
   ll_m++
   hpb_1.position = ll_m / al_copycount * 100
  else //本地文件存在的,比较文件时间
   ll_filehandle2 = FindFirstFileA(ls_filename2,ss_file2)
   FindClose(ll_filehandle2)
   choose case CompareFileTime(ss_file1.ftlastwritetime,ss_file2.ftlastwritetime)
    case 0
     //两个时间相等,就返回零
    case 1
     //如lpFileTime2小于lpFileTime1,返回1
     //下载
     lb_find = FtpGetFileA(ll_hftp1,ss_file1.cfilename,ls_filename2,false,0,0,0)
     ll_m++
     hpb_1.position = ll_m / al_copycount * 100
    case -1
     //如lpFileTime1小于lpFileTime2,返回-1
   end choose
  end if
 end if
loop
InternetCloseHandle(ll_hret);
InternetCloseHandle(ll_hftp1);
InternetCloseHandle(ll_fftp1);
return 1

end function

PB使用WININET的FTP方式自动更新(四、下载)相关推荐

  1. 后盾网lavarel视频项目---phpstorm 配置ftp, 自动更新同步代码

    后盾网lavarel视频项目---phpstorm 配置ftp, 自动更新同步代码 一.总结 一句话总结: 1.在phpstorm中设置:路径Tools/Deployment/Configuratio ...

  2. phpstorm 配置ftp, 自动更新同步代码 (亲测完美)

    phpstorm配置ftp,自动更新代码 2017年01月16日 11:50:44 阅读数:2115 第一步:Tools->Deployment->configruation 第二步:填写 ...

  3. UniAPP 安卓应用版本自动更新及下载安装

    一. 前言 近期进行 Uniapp 的开发,在项目发布的最后需要实现版本的自动检测和更新下载功能 特地在此进行文章的整理,以方便道友们减少前进道路上的坎坷,多谢指摘 - 注: 本次指导,以更新 安卓应 ...

  4. mysql更新下载文件在哪儿_Windows自动更新所下载的文件存在什么地方

    展开全部 自动更新下载的文件位于 C:\Windows\SoftwareDistribution\Download文件夹中. 这些文件占用空间并不很大,不必清除,62616964757a6869646 ...

  5. CleanAOP实战系列--WPF中MVVM自动更新

    CleanAOP实战系列--WPF中MVVM自动更新 作者: 立地 邮箱: jarvin_g@126.com QQ: 511363759 CleanAOP介绍:https://github.com/J ...

  6. wsus服务器推送指定的补丁,【补丁更新】组策略实现WSUS客户端自动更新

    使用组策略来管理 WSUS 自动更新客户端下载.安装和重新启动行为 可以配置 Windows Server Update Services (WSUS) 客户端来提供最符合您的环境和业务需求的更新安装 ...

  7. android通知栏应用程序更新,Android App自动更新之通知栏下载

    本文实例为大家分享了Android App自动更新通知栏下载的具体代码,供大家参考,具体内容如下 版本更新说明 这里有调用UpdateService启动服务检查下载安装包等 1. 文件下载,下完后写入 ...

  8. API v3版微信支付平台证书获取与自动更新

    API v3版微信支付平台证书获取与自动更新 关于微信证书 获取平台证书 证书自动更新 首次下载证书 关于微信证书 微信支付开发有两份证书. ♥ 商户证书:商户平台证书私钥可以对请求进行签名,微信服务 ...

  9. 自动更新之安装apk

    apk内部自动更新,下载apk后安装apk的逻辑,优点就是安装过程中,不会回退到桌面(有闪退的效果,其实不是闪退,是APP原来的进程被杀死了),安装完成后能显示完成和打开,且适配安卓7.0 //安装下 ...

最新文章

  1. Oracle表空间文件损坏后的排查及解决
  2. Spring5参考指南:JSR 330标准注解
  3. Python sqrt() 函数
  4. 数据结构课上笔记10
  5. java从1开始计时用线程_java – Python – 线程,计时或函数使用?
  6. 浅谈:飞秋 程序设计之网络通信
  7. 支付宝超硬硬件发布: 将颠覆现有支付方式!
  8. 推荐阅读20100708
  9. CS224N笔记——高级词向量表示
  10. java1.8 64_jdk 1.8 64位 官方版
  11. 寻找可接入正版音乐曲库的音乐API?来了解HIFIVE音乐开放平台!
  12. 开发人员必知!什么是Scrum敏捷开发?
  13. 小米oj和为零的三元组
  14. Arcgispro2.5安装教程
  15. tds与oracle,oracle和sqlserver找不到字段的错误
  16. Android实现SIM卡2拨打,android – 在双SIM卡设备中使用指定的SIM拨...
  17. python最佳ide_2014年最佳PHP IDE-调查结果
  18. 工作三年后,我选择离开腾讯
  19. jsp70918教务排课课程管理系统 mysql
  20. 基于easyX和vs使用c++绘制坐标系以及实时显示

热门文章

  1. 系统找不到zlib.dll文件的解决方法。zlib编译和使用
  2. arduino uno模拟遥控器控制无刷电机
  3. 移动端手机调试的方法
  4. 「产品读书」俞军产品方法论
  5. 真正的互联网诞生:TCP/IP协议的出现
  6. 也谈智能手机游戏开发中的分辨率自适应问题
  7. charles安装证书并信任证书,仍然无法获取手机上的请求
  8. java读写word文档,完美解决方案
  9. 阿里云天池大赛赛题解析——机器学习篇 | 留言赠书
  10. 云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)