分享
 
 
 

用vb实现ftp的上传下载

王朝vb·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Option Explicit

Public 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

Public 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

Public 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

Public 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

Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _

(ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean

Public Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _

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

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Public 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

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _

(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long

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 "comdlg32.dll" Alias _

"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

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, "ip地址", 0, _

"用户名", "密码", 1, 0, 0)

If lnginetconn Then

blnRC = FtpGetFile(lnginetconn, "website/address.asp", "c:\address.asp", 0, 0, 1, 0)

If blnRC Then

MsgBox "download ok!!!"

End If

InternetCloseHandle lnginetconn

InternetCloseHandle lnginet

MsgBox "close ok!!!"

Else

MsgBox "can't connect"

End If

Else

MsgBox "ftp wrong"

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, "IP地址", 0, _

"用户名", "密码", 1, 0, 0)

If lnginetconn Then

lngHINet = FtpFindFirstFile(lnginetconn, "*.*", pData, 0, 0)

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有