7,763
社区成员
发帖
与我相关
我的任务
分享
Function FtpConnect() As Boolean '连接FTP
Dim hOpen As Long
If Err.Number <> 0 Then Err.Clear
If hConnection = 0 Then
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
hConnection = InternetConnect(hOpen, "**.**.**.**", _
INTERNET_INVALID_PORT_NUMBER, "***", "***", _
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
FtpConnect = CBool(hConnection)
Debug.Print "FtpConnect=" & FtpConnect
' Debug.Print hConnection
End If
End Function
Public Function DownloadFile(ByVal LocalFile As String, ByVal RemoteFile As String) As Boolean '下载指定文件
If FtpConnect Then '如果连接成功
DownloadFile = FtpGetFile(hConnection, "服务器路径及文件名", "本地路径及文件名", 0, 0, 0, 0)
Else
DownloadFile = False
End If
InternetCloseHandle hConnection
DisConnect
End Function
Function DisConnect() As Boolean '关闭连接
DisConnect = True
If hConnection <> 0 Then
hConnection = 0
DisConnect = CBool(InternetCloseHandle(hConnection))
End If
End Function