Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _
ByVal SProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _
(ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
(ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, _
ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFilAttributes 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
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function F_ftp_getfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
F_ftp_getfile = ""
Dim lnginet
Dim lnginetconn
Dim blnRC
Dim lpFileData As WIN32_FIND_DATA
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
If lnginetconn Then
blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0)
If blnRC Then
F_ftp_getfile = "1"
Else
F_ftp_getfile = "0"
End If
Else
F_ftp_getfile = "0"
End If
Else
End If
InternetCloseHandle lnginetconn
InternetCloseHandle lnginet
End Function
Public Function F_ftp_putfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
F_ftp_putfile = ""
Dim lnginet
Dim lnginetconn
Dim blnRC
Dim aa As Long
Dim lpFileData As WIN32_FIND_DATA
lpFileData.cFileName = String(260, 0)
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
If lnginetconn Then
aa = FtpFindFirstFile(lnginetconn, remotefile, lpFileData, 0, 0)
blnRC = FtpPutFile(lnginetconn, ftpfile, remotefile, 1, 0)
If blnRC Then
F_ftp_putfile = "1"
Else
F_ftp_putfile = "0"
End If
Else
F_ftp_putfile = "0"
End If
Else
End If
InternetCloseHandle lnginetconn
InternetCloseHandle lnginet
End Function
Public Function F_ftp_getMfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
F_ftp_getMfile = ""
Dim lnginet
Dim lnginetconn
Dim blnRC
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
If lnginetconn Then
blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0)
If blnRC Then
F_ftp_getMfile = "1"
Else
F_ftp_getMfile = "0"
End If
Else
F_ftp_getMfile = "0"
End If
Else
End If
InternetCloseHandle lnginetconn
InternetCloseHandle lnginet
End Function
VB 文件传输函数(版本自动更新用 MY_FILE_FTP.cls)
点赞
收藏