'FTP下載檔案
Public Function DownLoadFile(IP As String, FileName As String, LocalFileName As String, UserName As String, PassWord As String, ByVal FtpSubdirectory As String) As Boolean
On Error GoTo f_Error
Dim Ret As Boolean
Dim FTP_FileName As String
If Len(FtpSubdirectory) > 0 Then
FTP_FileName = "\" & Trim(FtpSubdirectory) & "\" & FileName
Else
FTP_FileName = FileName
End If
hOpen = TestServer
If hOpen <> 0 Then
hConnection = InterConnection(IP, UserName, PassWord)
If hConnection <> 0 Then
' ret = FtpGetFile(hConnection, FileName, LocalFileName, 0, 0, 1, 0)
' DownLoadFile = ret
FtpGetFile hConnection, FTP_FileName, LocalFileName, 0, 0, 2, 0
' 第一個引數hFtpSession 是InternetConnect 呼叫回傳的句柄值。
' lpszRemoteFile和lpszNewFile 分別是FTP服務器上的檔案名和將在本地機上創建的檔案名?
' fFailIfExists 標志是0(替換本地檔案)或1 (如果本地檔案已經存在則取消)。
' dwFlagsAndAttributes 用來指定本地檔案的檔案屬性?
' dwFlags 引數指定為1是用ASCII 傳輸檔案(A類傳輸方法),指定為2是用二進制傳輸檔案(1類傳輸方法)。
' 最后,當使用回叫信號時,lContext 用來識別應用程式前后關系。
' 如果函式呼叫成功,blnRC為 True, 反之為False。
DownLoadFile = (GetLastError <> ERROR_INTERNET_EXTENDED_ERROR)
Else
DownLoadFile = False
End If
Else
DownLoadFile = False
End If
InternetCloseHandle hConnection
InternetCloseHandle hOpen
Exit Function
f_Error:
MsgBox "錯誤碼:" & err.Number & Chr(13) & err.Source & ":" & err.Description, vbExclamation, "提示"
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/248722.html
標籤:VB基礎類
上一篇:VBA 可見單元格行數獲取問題
