20170920xlVBA_FTP_UpDownLoad_DownLoad
'建立应用环境进程
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
'连接层,连接服务器
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
'切换目录
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
'查找函数
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
'查找数据结构
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As Currency
ftLastAccessTime As Currency
ftLastWriteTime As Currency
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
'下载函数
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
'上传文件
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
'断开链接
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Function DownLoadFile() As Boolean
'建立环境
lngINet = InternetOpen("My Ftp", 1, vbNullString, vbNullString, 0)
Debug.Print lngINet
'链接服务器
lngINetConn = InternetConnect(lngINet, host_url, 0, user_name, pass_word, 1, 0, 0)
'Debug.Print lngINetConn
If lngINetConn = 0 Then
MsgBox "连接服务器失败!", vbInformation, "NextSeven"
DownLoadFile = False
GoTo FailTag1
End If
'切换目录
cngdir = FtpSetCurrentDirectory(lngINetConn, root_folder & sub_folder) '目录
If cngdir = False Then
MsgBox "切换目录失败!", vbInformation, "NextSeven"
DownLoadFile = False
GoTo FailTag1
End If
Debug.Print cngdir '查找首个文件
Dim pData As WIN32_FIND_DATA
Dim FileName As String
FileName = remote_file
lngHINet = FtpFindFirstFile(lngINetConn, FileName, pData, 0, 0) If lngHINet = 0 Then
MsgBox "查找文件失败!", vbInformation, "NextSeven"
DownLoadFile = False
GoTo FailTag1
End If strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
blnRc = FtpGetFile(lngINetConn, strTemp, local_file_path, 0, 0, 1, 0)
If blnRc Then
DownLoadFile = True
Debug.Print "下载成功"
Else
Debug.Print "下载失败"
DownLoadFile = False
End If FailTag1:
InternetCloseHandle lngINetConn
FailTag2:
InternetCloseHandle lngINet
End Function
Public Function UpLoadFile() As Boolean
'建立环境
lngINet = InternetOpen("My Ftp", 1, vbNullString, vbNullString, 0)
Debug.Print lngINet
'链接服务器
lngINetConn = InternetConnect(lngINet, host_url, 0, user_name, pass_word, 1, 0, 0)
'Debug.Print lngINetConn
If lngINetConn = 0 Then
MsgBox "连接服务器失败!", vbInformation, "NextSeven"
UpLoadFile = False
GoTo FailTag1
End If
'切换目录
cngdir = FtpSetCurrentDirectory(lngINetConn, root_folder & sub_folder) '目录
If cngdir = False Then
MsgBox "切换目录失败!", vbInformation, "NextSeven"
UpLoadFile = False
GoTo FailTag1
End If
Debug.Print cngdir '查找首个文件
Dim pData As WIN32_FIND_DATA
Dim FileName As String
FileName = remote_file
'上传文件
blnRc = FtpPutFile(lngINetConn, local_file_path, FileName, 1, 0)
If blnRc Then
Debug.Print "上传成功"
UpLoadFile = True
Else
Debug.Print "上传失败"
UpLoadFile = False
End If
'断开
FailTag1:
InternetCloseHandle lngINetConn
FailTag2:
InternetCloseHandle lngINet
End Function
20170920xlVBA_FTP_UpDownLoad_DownLoad的更多相关文章
随机推荐
- Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
centos7.5 安装mysql数据库报错 问题: [root@db04-54 scripts]# /etc/init.d/mysqld start /etc/init.d/mysqld: line ...
- POP-OOP-SOP-COP-SOA-AOP
一.面向过程 二.面向对象 三.面向服务 四.补充 五.总结: 英文及缩写: 面向过程:procedure oriented programming POP 面向对象:object oriented ...
- SpringBoot 解决HttpServletRequest只能读取一次
业务逻辑,通过filter读取请求的request,获取token,并将token传递后面流程使用 BodyReaderHttpServletRequestWrapper: public class ...
- NLP--- How to install the tool NLTK in Ubuntu ?
NLP--- How to install the tool NLTK in Ubuntu ? 1. open the website of NLTK and download it. https: ...
- 用.native修饰器来对外部组件进行构造器内部方法的调用以及用原生js获取构造器里的方法
html <div id="app"> <span v-text="number"></span> <btn @cli ...
- Java 11 究竟比 8 快了多少?看看这个基准测试
开源规划调度引擎 OptaPlanner 官网发布了一个 Java 11 GC 性能基准测试报告. 当前使用量最大的 Java 版本是 8,所以测试者用 Java 8 与 Java 11 进行对比测试 ...
- ffmpeg 下载安装和简单应用
一.ffmpeg下载 先到http://ffmpeg.org/下载ffmpeg安装文件 二.ffmpeg安装 1.解压下载完的ffmpeg-20190319-f8075b2-win64-shared. ...
- 【matlab】笔记_1
基本操作 ans 最近计算的答案 clc 清除命令行窗口 diary 将命令行窗口文本保存到文件中 矩阵 用逗号 (,) 或空格分隔各行元素. 用分号(;)分隔各列元素. a':装置矩阵. 要执行元素 ...
- facebook api之基本概念(中文)
Facebook广告API系列 1 Facebook Graph API Facebook提供了一套类rest的接口,统称为Graph API.为啥叫Graph?因为facebook把所有的资源都抽象 ...
- java 注解的使用
@Target({ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Without ...