Public Function ConnectFTP(Optional ByVal vsFTPIPAdress As String, Optional vsUid As String = "", _ Optional vsPwd As String = "", Optional vsPort As String = "21") As Boolean Dim site As FtpInfo ConnectFTP = False site.FtpIP = vsFTPIPAdress site.UID = vsUid site.PWD = vsPwd '调用格式检查,并将FTP信息保存到本地变量 If Len(site.FtpIP) = 0 Then Err.Raise vbObjectError + 1, "ConnectFTP", "No IP Address!" End If '打开会话 mlOpenHandle = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, _ vbNullString, 2) If mlOpenHandle = 0 Then ErrorOut Err.LastDllError, "InternetOpen" Exit Function End If '连接FTP服务器 Dim INTERNET_FLAG As Long 'If gbFtpCache Then INTERNET_FLAG = INTERNET_FLAG_DONT_CACHE 'Else ' INTERNET_FLAG = INTERNET_FLAG_OFFLINE 'End If mlConnectionHandle = InternetConnect(mlOpenHandle, site.FtpIP, vsPort, _ site.UID, site.PWD, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, INTERNET_FLAG) 'xram If mlConnectionHandle = 0 Then mbActiveSession = False Exit Function Else mbActiveSession = True End If ConnectFTP = True End Function