VB与FTP编程
来源:百度文库 编辑:神马文学网 时间:2024/04/25 17:43:21
Option Explicit
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const scuseragent = "vb wininet"
Private Const INTERNET_FLAG_PASSIVE = &H8000000
'调用设置环境
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 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 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 InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Dim hOpen As Long
Dim hConnection As Long
'上传文件模块
Public Function UpLoadFile(IP As String, FileName As String, UserName As String, PassWord As String) As Boolean
Dim ShortName As String
Dim ret As Boolean
ShortName = GetShortName(FileName)
hOpen = TestServer
If hOpen <> 0 Then
hConnection = InterConnection(IP, UserName, PassWord)
If hConnection <> 0 Then
ret = FtpPutFile(hConnection, FileName, ShortName, 2, 0)
UpLoadFile = ret
Else
UpLoadFile = False
End If
Else
UpLoadFile = False
End If
InternetCloseHandle hConnection
InternetCloseHandle hOpen
End Function
'FTP下载文件
Public Function DownLoadFile(IP As String, FileName As String, LocalFileName As String, UserName As String, PassWord As String)
Dim ret As Boolean
hOpen = TestServer
If hOpen <> 0 Then
hConnection = InterConnection(IP, UserName, PassWord)
If hConnection <> 0 Then
ret = FtpGetFile(hConnection, FileName, LocalFileName, 0, 0, 1, 0)
DownLoadFile = ret
Else
DownLoadFile = False
End If
Else
DownLoadFile = False
End If
InternetCloseHandle hConnection
InternetCloseHandle hOpen
End Function
'调用设置环境
Private Function TestServer() As Long
Dim i As Long
' i = InternetOpen(scuseragent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
i = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
TestServer = i
End Function
'连接服务器
Private Function InterConnection(IP As String, UserName As String, PassWord As String) As Long
Dim i As Long
i = InternetConnect(hOpen, IP, 0, UserName, PassWord, 1, INTERNET_FLAG_PASSIVE, 0)
InterConnection = i
End Function
'得到文件的短文件名
Private Function GetShortName(FileName As String) As String
Dim stemp() As String
stemp = Split(FileName, "\")
If UBound(stemp) > 0 Then
GetShortName = stemp(UBound(stemp))
Else
GetShortName = ""
End If
End Function
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const scuseragent = "vb wininet"
Private Const INTERNET_FLAG_PASSIVE = &H8000000
'调用设置环境
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 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 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 InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Dim hOpen As Long
Dim hConnection As Long
'上传文件模块
Public Function UpLoadFile(IP As String, FileName As String, UserName As String, PassWord As String) As Boolean
Dim ShortName As String
Dim ret As Boolean
ShortName = GetShortName(FileName)
hOpen = TestServer
If hOpen <> 0 Then
hConnection = InterConnection(IP, UserName, PassWord)
If hConnection <> 0 Then
ret = FtpPutFile(hConnection, FileName, ShortName, 2, 0)
UpLoadFile = ret
Else
UpLoadFile = False
End If
Else
UpLoadFile = False
End If
InternetCloseHandle hConnection
InternetCloseHandle hOpen
End Function
'FTP下载文件
Public Function DownLoadFile(IP As String, FileName As String, LocalFileName As String, UserName As String, PassWord As String)
Dim ret As Boolean
hOpen = TestServer
If hOpen <> 0 Then
hConnection = InterConnection(IP, UserName, PassWord)
If hConnection <> 0 Then
ret = FtpGetFile(hConnection, FileName, LocalFileName, 0, 0, 1, 0)
DownLoadFile = ret
Else
DownLoadFile = False
End If
Else
DownLoadFile = False
End If
InternetCloseHandle hConnection
InternetCloseHandle hOpen
End Function
'调用设置环境
Private Function TestServer() As Long
Dim i As Long
' i = InternetOpen(scuseragent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
i = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
TestServer = i
End Function
'连接服务器
Private Function InterConnection(IP As String, UserName As String, PassWord As String) As Long
Dim i As Long
i = InternetConnect(hOpen, IP, 0, UserName, PassWord, 1, INTERNET_FLAG_PASSIVE, 0)
InterConnection = i
End Function
'得到文件的短文件名
Private Function GetShortName(FileName As String) As String
Dim stemp() As String
stemp = Split(FileName, "\")
If UBound(stemp) > 0 Then
GetShortName = stemp(UBound(stemp))
Else
GetShortName = ""
End If
End Function
VB与FTP编程
VB编程技巧码
VB编程基础
VB数据库编程技术
VB数据库编程技术!
VB编程的必备技巧
编程入门网-Vb教程
VB数据库编程技术123
利用Winsock控件实现FTP编程
VB编程的七个优良习惯
VB数据库编程书写经验两则
功能强大的SendMessage函数 vb编程
VB编程(输入法、数据转制)
VB.Net编程入门之Hello World
VB的API编程精粹123
自由与意义vb
Matlab与VB集成
FTP
FTP
ftp
Linux Ftp服务器软件wu-ftp与vsftpd
关于combobox的问题 - VB.NET - 编程街
VB编程基础教程1–编码基础 | 异次元软件世界
VB编程基础教程5–静态变量 | 异次元软件世界