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的更多相关文章
随机推荐
- 关于BOARD_SYSTEMIMAGE_PARTITION_SIZE【转】
本文转载自:https://blog.csdn.net/ttxgz/article/details/7542380 1. 系统需要,把需要预置在系统的所有apk放在目录 device/softwinn ...
- JPush Flutter Plugin(Futter推送-极光推送)
https://pub.flutter-io.cn/packages/jpush_flutter JPush's officially supported Flutter plugin (Androi ...
- P5057 [CQOI2006]简单题(线段树)
果然简单题,5分钟紫题++ 代码 #include <cstdio> #include <algorithm> #include <cstring> using n ...
- 《开始使用Linux》单元测验 1
C语言编写的应用程序,通过printf打印一个换行符\n,但在终端上执行的是回车加换行\r\n,把换行符替换为回车换行是由下面哪个软件模块完成的? Linux内核中的行律模块 下面哪个命令可以获得ma ...
- B树,B+树比较
首先注意:B树就是B-树,"-"是个连字符号,不是减号.也就是B-树其实就是B树 B-树是一种平衡的多路查找(又称排序)树,在文件系统中有所应用.主要用作文件的索引.其中的B就表示 ...
- Images之Dockerfile中的命令1
Dockerfile reference Docker can build images automatically by reading the instructions from a Docker ...
- A Simple Note on "P4FPGA: A Rapid Prototyping Framework for P4"
论文:P4FPGA: A Rapid Prototyping Framework for P4 Github:https://github.com/p4fpga Reference: Han Wang ...
- Sublime Text 查找时排除指定的文件夹或文件
Sublime Text 查找时排除指定的文件夹或文件 Ctrl + Shift + F这组快捷键可以调出 Sublime Text 的查找替换窗口,里边有一栏 Where,可以做一些高级设置:d:\ ...
- vs项目的属性页面总结
本文主要针对vs中属性页面的相关选项含义进行了总结.
- VirtualBox-- 虚拟机网络设置2--主机与虚拟机互相访问且均上外网
转载自:http://blog.sina.com.cn/s/blog_7de9d5d80100t2uw.html VirtualBox中有4中网络连接方式:NATBridged AdapterIn ...