用vb实现ftp的上传下载

更新时间:2023-10-28 05:25:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Option Explicit

Public Declare Function InternetOpen Lib \

(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _ ByVal SProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib \(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

Public Declare Function FtpGetFile Lib \(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

Public Declare Function FtpPutFile Lib \(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean

Public Declare Function FtpDeleteFile Lib \ (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean

Public Declare Function FtpRenameFile Lib \

(ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean

Public Declare Function InternetCloseHandle Lib \

Public Declare Function FtpFindFirstFile Lib \ (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _

lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, _ ByVal dwContent As Long) As Long

Public Declare Function InternetFindNextFile Lib \(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long

Const INTERNET_OPEN_TYPE_PRECONFIG = 0

Public Type FILETIME

dwLowDateTime As Long

dwHighDateTime As Long End Type

Public 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

Public Declare Function GetOpenFileName Lib \

\

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

Private Sub Command1_Click()

lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _ vbNullString, vbNullString, 0&)

If lnginet Then

lnginetconn = InternetConnect(lnginet, \地址\ \用户名\密码\ If lnginetconn Then

blnRC = FtpGetFile(lnginetconn, \ If blnRC Then

MsgBox \ End If

InternetCloseHandle lnginetconn InternetCloseHandle lnginet MsgBox \ Else

MsgBox \ End If Else

MsgBox \End If End Sub

Private Sub Command2_Click() Dim pData As WIN32_FIND_DATA Dim lngHINet As Long Dim intError As Integer Dim strTemp As String Dim blnRC As Boolean

pData.cFileName = String(260, 0)

lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _ vbNullString, vbNullString, 0&) If lnginet Then

lnginetconn = InternetConnect(lnginet, \地址\ \用户名\密码\ If lnginetconn Then

lngHINet = FtpFindFirstFile(lnginetconn, \

strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1) Do

pData.cFileName = String(260, 0)

blnRC = InternetFindNextFile(lngHINet, pData) If Not blnRC Then Exit Do Else

strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1) End If

Loop

Text1.Text = strTemp End If End If

InternetCloseHandle lngHINet

InternetCloseHandle lnginetconn InternetCloseHandle lnginet End Sub

本文来源:https://www.bwwdw.com/article/j6q2.html

Top