1Option Explicit 2 3Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _ 4(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _ 5ByVal SProxyBypass As String, ByVal lFlags As Long) As Long 6 7Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _ 8(ByVal hInternetSession As Long, ByVal sServerName As String, _ 9ByVal nServerPort As Integer, ByVal sUsername As String, _ 10ByVal sPassword As String, ByVal lService As Long, _ 11ByVal lFlags As Long, ByVal lContext As Long) As Long 12 13Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _ 14(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _ 15ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _ 16ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _ 17ByVal dwContext As Long) As Boolean 18 19Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _ 20(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _ 21ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _ 22ByVal dwContext As Long) As Boolean 23 24Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _ 25 (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean 26 27Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _ 28 (ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean 29 30Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer 31 32Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _ 33 (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _ 34 lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, _ 35 ByVal dwContent As Long) As Long 36 37Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _ 38(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long 39 40Const INTERNET_OPEN_TYPE_PRECONFIG = 0 41 42Private Type FILETIME 43 dwLowDateTime As Long 44 dwHighDateTime As Long 45End Type 46Private Type WIN32_FIND_DATA 47 dwFilAttributes As Long 48 ftCreationTime As FILETIME 49 ftLastAccessTime As FILETIME 50 ftLastWriteTime As FILETIME 51 nFileSizeHigh As Long 52 nFileSizeLow As Long 53 dwReserved0 As Long 54 dwReserved1 As Long 55 cFileName As String * 260 56 cAlternate As String * 14 57End Type 58 59Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ 60 "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long 61 62Private Type OPENFILENAME 63 lStructSize As Long 64 hwndOwner As Long 65 hInstance As Long 66 lpstrFilter As String 67 lpstrCustomFilter As String 68 nMaxCustFilter As Long 69 nFilterIndex As Long 70 lpstrFile As String 71 nMaxFile As Long 72 lpstrFileTitle As String 73 nMaxFileTitle As Long 74 lpstrInitialDir As String 75 lpstrTitle As String 76 flags As Long 77 nFileOffset As Integer 78 nFileExtension As Integer 79 lpstrDefExt As String 80 lCustData As Long 81 lpfnHook As Long 82 lpTemplateName As String 83End Type 84 85Public Function F_ftp_getfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String 86 F_ftp_getfile = "" 87 Dim lnginet 88 Dim lnginetconn 89 Dim blnRC 90 Dim lpFileData As WIN32_FIND_DATA 91 lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&) 92 If lnginet Then 93 lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0) 94 If lnginetconn Then 95 blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0) 96 If blnRC Then 97 F_ftp_getfile = "1" 98 Else 99 F_ftp_getfile = "0" 100 End If 101 Else 102 F_ftp_getfile = "0" 103 End If 104 Else 105 End If 106 InternetCloseHandle lnginetconn 107 InternetCloseHandle lnginet 108End Function 109 110Public Function F_ftp_putfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String 111 F_ftp_putfile = "" 112 Dim lnginet 113 Dim lnginetconn 114 Dim blnRC 115 Dim aa As Long 116 Dim lpFileData As WIN32_FIND_DATA 117 lpFileData.cFileName = String(260, 0) 118 lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&) 119 If lnginet Then 120 lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0) 121 If lnginetconn Then 122 aa = FtpFindFirstFile(lnginetconn, remotefile, lpFileData, 0, 0) 123 blnRC = FtpPutFile(lnginetconn, ftpfile, remotefile, 1, 0) 124 If blnRC Then 125 F_ftp_putfile = "1" 126 Else 127 F_ftp_putfile = "0" 128 End If 129 Else 130 F_ftp_putfile = "0" 131 End If 132 Else 133 End If 134 InternetCloseHandle lnginetconn 135 InternetCloseHandle lnginet 136End Function 137 138 139Public Function F_ftp_getMfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String 140 F_ftp_getMfile = "" 141 Dim lnginet 142 Dim lnginetconn 143 Dim blnRC 144 lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&) 145 If lnginet Then 146 lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0) 147 If lnginetconn Then 148 blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0) 149 If blnRC Then 150 F_ftp_getMfile = "1" 151 Else 152 F_ftp_getMfile = "0" 153 End If 154 Else 155 F_ftp_getMfile = "0" 156 End If 157 Else 158 End If 159 InternetCloseHandle lnginetconn 160 InternetCloseHandle lnginet 161End Function
VB 文件传输函数(版本自动更新用 MY_FILE_FTP.cls)
Wesley13
2021-10-11
1382 0 0
点赞
收藏
评论区
加载中...