1,502
社区成员
发帖
与我相关
我的任务
分享
Public Function GetFile&(ByVal HostFile$, _
ByVal ToLocalFile$, _
Optional tt As FileTransferType = fttUnknown)
'Get the specified file and move to the desired location using
'[optional] specified file transfer type
On Local Error GoTo Handler
Dim ReturnVal&
Dim remotefile$
Dim RemoteDir$
Dim LocalFile$
Dim pos&
Dim ErrMsg$
GetFile& = FAILURE&
'If not connected, raise an error
If m_hSession& = NO_CONNECTION& Then
Err.Raise ERR_NOT_CONNECTED_TO_SITE, "clsFTP:GetFile", ERR_NO_CONNECTION$
End If
'Get the file
ReturnVal& = FtpGetFile(m_hSession&, HostFile$, _
ToLocalFile$, False, INTERNET_FLAG_RELOAD, tt, 0)
If ReturnVal& = FAILURE& Then
ErrMsg$ = Replace(ERR_DOWNLOAD$, "%s", HostFile$)
Err.Raise ERR_CANNOT_GET_FILE, "clsFTP:GetFile", ErrMsg$
End If
GetFile& = SUCCESS&
ExitProc:
Exit Function
Handler:
GetFile& = Err.Number
Resume ExitProc
End Function
Private Declare Function FtpGetFile Lib "wininet.dll" _
Alias "FtpGetFileA" _
(ByVal hOutboundSession&, _
ByVal lpszRemoteFile$, _
ByVal lpszNewFile$, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes&, _
ByVal dwFlags&, _
ByVal dwContext&) As Boolean
Private Sub btn_Down_Click()
Dim fileID As Integer
Dim str As String
If FTP.IsConnected = True Then
If FTP.FindFirstFile("up.txt") = 1 Then'服务器上存在此文件
If Dir(App.Path & "\DownLoad.txt") <> "" Then
Kill App.Path & "\DownLoad.txt"
End If
Call FTP.GetFile("up.txt", App.Path & "\DownLoad.txt")'下载
fileID = FreeFile(1)
Open App.Path & "\DownLoad.txt" For Input As #fileID
Line Input #fileID, str
Me.txt_DownLoad.Text = str
Close #fileID
End If
Else
MsgBox Err.Descriptio
End If
End Sub