日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

VB與FTP編程

 昵稱1668811 2010-06-17
Option Explicit
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const scuseragent = "vb wininet"
Private Const INTERNET_FLAG_PASSIVE = &H8000000
'調(diào)用設(shè)置環(huán)境
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
'連接服務(wù)器
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
'上傳涵數(shù)
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
'調(diào)用設(shè)置環(huán)境
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
'連接服務(wù)器
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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多