Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

[5分]请帮我注释下这段FTP服务器上传下载数据的代码

咖啡加冰  发表于:2009-05-04 22:22:27  
复制

我的程序中有个模块需要从FTP服务器上传下载数据,好不容易找到了一段代码,但是能力有限看不懂。请高手帮我注释下。谢谢。

用ACCESS向Ftp服务器上传文件

用API调用:

'声明:
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 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 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 InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

'函数
Private Function UpLoadFile(ByVal LocateFile As String, ByVal RemoteFile As String) As Boolean
Dim lngINet As Long, lngINetConn As Long, blnRC As Boolean
'Me.lbMsg.Caption = "打开INTERNET句柄"
'Me.Repaint
lngINet = InternetOpen("FTP", 1, vbNullString, vbNullString, 0)
If lngINet = 0 Then Exit Function
'Me.lbMsg.Caption = "连接远程主机"
'Me.Repaint
lngINetConn = InternetConnect(lngINet, "IP地址", 端口, "用户", "密码", 1, 0, 0)
If lngINetConn = 0 Then Exit Function
'Me.lbMsg.Caption = "上传文件"
'Me.Repaint
blnRC = FtpPutFile(lngINetConn, LocateFile, RemoteFile, 1, 0)
If blnRC = False Then Exit Function
'Me.lbMsg.Caption = "上传成功"
'Me.Repaint
InternetCloseHandle lngINetConn
InternetCloseHandle lngINet
UpLoadFile = True
'Me.lbMsg.Caption = ""
End Function


Private Function DownLoadFile(ByVal RemoteFile As String, ByVal LocateFile As String) As Boolean
Dim lngINet As Long, lngINetConn As Long, blnRC As Boolean
'Me.lbMsg.Caption = "打开INTERNET句柄..."
'Me.Repaint
lngINet = InternetOpen("FTP", 1, vbNullString, vbNullString, 0)
If lngINet = 0 Then Exit Function
'Me.lbMsg.Caption = "连接远程主机..."
'Me.Repaint
lngINetConn = InternetConnect(lngINet, "IP地址", 端口, "帐号", "密码", 1, 0, 0)
If lngINetConn = 0 Then Exit Function
'Me.lbMsg.Caption = "正在下载文件..."
'Me.Repaint
blnRC = FtpGetFile(lngINetConn, RemoteFile, LocateFile, False, 0, 1, 0)
If blnRC = False Then Exit Function
'Me.lbMsg.Caption = "下载成功"
'Me.Repaint
InternetCloseHandle lngINetConn
InternetCloseHandle lngINet
DownLoadFile = True
End Function

 

Top
竹笛 发表于:2009-05-04 22:44:00

哈,全部照抄即可,放在一个窗体中,只需要注意一行代码就可以了:

lngINetConn = InternetConnect(lngINet, "IP地址", 端口, "帐号", "密码", 1, 0, 0)

 

实际使用时,举例为:

lngINetConn = InternetConnect(lngINet, "222.35.79.188", 21, "myftpaccess", "mypassord", 1, 0, 0)

 

调用方法:

Call DownLoadFile("down/01.rar", "c:\01.rar") '将ftp中down文件夹中的01.rar下载到本地电脑c:\01.rar



总记录:1篇  页次:1/1 9 1 :