使用以的类模块:
将以内容保存为一个文件:clsFTP.cls
由于太长不能在一个贴子放下,所以分了几部分:
Part1:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsFTP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'Copyright Graham Daly December 2001
' ---------------------------------------------------------
' ------------------- API Functions --------------------
' ---------------------------------------------------------
'File time information
Private Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
'File information
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
'Wininet.dll API's
Private Declare Function FtpFindFirstFile& Lib "wininet.dll" _
Alias "FtpFindFirstFileA" _
(ByVal hOutboundSession&, _
ByVal lpszSearchFile$, _
lpFindFileData As WIN32_FIND_DATA, _
ByVal dwFlags&, _
ByVal dwContent&)
Private Declare Function InternetFindNextFile& Lib "wininet.dll" _
Alias "InternetFindNextFileA" _
(ByVal hFind&, _
lpvFindData As WIN32_FIND_DATA)
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 Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" _
(ByVal hOutboundSession&, _
ByVal lpszLocalFile$, _
ByVal lpszRemoteFile$, _
ByVal dwFlags&, _
ByVal dwContext&) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" _
Alias "FtpRenameFileA" _
(ByVal hOutboundSession&, _
ByVal sExistingName$, _
ByVal sNewName$) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" _
(ByVal hOutboundSession&, _
ByVal lpszFileName$) As Boolean
Private Declare Function FtpGetCurrentDirectory& Lib "wininet.dll" _
Alias "FtpGetCurrentDirectoryA" _
(ByVal hConnect&, _
ByVal lpszCurrentDirectory$, _
lpdwCurrentDirectory&)
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" _
Alias "FtpSetCurrentDirectoryA" _
(ByVal hOutboundSession&, _
ByVal lpszDirectory$) As Boolean