(VB)FTP异步下载
该方法不需要使用API及第三方控件
这里使用的是VB的UserControl控件的AsyncRead方法
步骤如下:
1、添加一个用户控件,设置InvisibleAtRuntime属性为true,目的是运行时该控件不显示用户界面,就象Timer控件一样。
2、到自定义控件的代码窗口,添加如下代码
Option Explicit
'下载结果枚举
Public Enum DownloadResults
eSUCCESS = 0 '下载成功
eCONNECTERROR = 1 '连接错误
eTRANSFERERROR = 2 '数据传输错误
eWRITEERROR = 3 '保存本地错误
eUserStop = 4 '中止
End Enum
'下载进度事件 Identifier-下载标识,RecvdBytes-已下载字节数,MaxBytes-总字节数,PassTimer-已用下载时间(秒)
Public Event DownloadProgress(Identifier As String, RecvdBytes As Long, MaxBytes As Long, PassTimer As Long)
'下载完成事件 Identifier-下载标识,ccDownloadResults-下载结果,PassTimer-已用下载时间(秒)
Public Event DownloadComplete(Identifier As String, Result As DownloadResults, PassTimer As Long)
Dim FstrURL As String 'FTP 下载字符串,含IP,端口号,用户名,密码,下载的文件及其路径
Dim FstrSaveFile As String '下载的文件保存在本地的文件名及其路径
Dim FstrIdentifier As String '下载标识
Dim FlngStart As Long '开始下载时间
'下载文件
'strURL FTP 下载字符串,含IP,端口号,用户名,密码,下载的文件及其路径
' 形如 ftp://用户名:密码@FTP地址/目录/文件
'strSaveFile 保存时的本地文件名
'strIdentifier 下载标识,可以同时下载多个文件,依据此字符串区别所下载的文件
Public Sub DownLoad(ByVal strURL As String, ByVal strSaveFile As String, ByVal strIdentifier As String)
On Error GoTo ERRHAND
FstrURL = strURL
FstrSaveFile = strSaveFile
FstrIdentifier = strIdentifier
FlngStart = Timer
UserControl.AsyncRead strURL, vbAsyncTypeByteArray, strIdentifier, vbAsyncReadForceUpdate
Exit Sub
ERRHAND:
RaiseEvent DownloadComplete(strIdentifier, eCONNECTERROR, Timer - FlngStart)
End Sub
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
On Error GoTo Errs
相关文档:
Public Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long
Public Declare Function VarPtrStringArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long
取对象地址: ObjPtr
取OLE对象的地址: OLE_NAME.LpOleObject
取函数地址: AddressOf
取字符串地址: StrPtr
取 ......
简单
在Global.asa文件中加入如下的代码:
Java代码
1. <SCRIPT LANGUAGE="VBScript" RUNAT="Server">
2.
3. Sub Application_OnStart
4.
5. '当服务器开启时,设置在线用户计数器为0
6. Application("ActiveUsers") = 0
7.
......
'引用:Microfoft VBScript Regular Expressions 5.5 '一个正则提取功能
Public Function regGetStr_three(ByVal myString As String, ByVal patReg As String) As String()
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As Ma ......
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
......