设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 10137|回复: 19
打印 上一主题 下一主题

[新4]用ACCESS向ftp服务器上传文件

[复制链接]
跳转到指定楼层
1#
发表于 2004-3-2 00:35:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
不调用任何ftp软件,只使用ACCESS编程实现。。。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
推荐
发表于 2004-6-11 16:39:00 | 只看该作者
用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 LongPrivate 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 BooleanPrivate 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
2#
 楼主| 发表于 2004-3-2 00:37:00 | 只看该作者
我想是否可以调用web浏览器直接打开ftp,然后复制所需文件,再粘贴到web浏览器,现在只能想到这样了,不知高手门有没有更好的办法。
3#
 楼主| 发表于 2004-3-2 22:16:00 | 只看该作者
另外一个做法:
直接用一个ole连接字段,然后把文件存进去。在界面上作个按钮,用代码插入ole连接对象,看起来就像上传一样,这样唯一的缺点就是数据库增大的很快,只能定期维护,我的解决的办法就是作一个按钮“查看”,打开文件的同时就将这个对象删除,以减小数据库的尺寸。请问那位有更好的办法???
5#
发表于 2004-6-11 21:46:00 | 只看该作者
晕, 这不把FTP软件的FTP代码都般过来了吗, hoho~
6#
发表于 2004-6-19 21:03:00 | 只看该作者
做到了题目就OK啦!为什么要介意这个?这种题目就好象说:我要你走路,但不准用脚走![em11]
7#
发表于 2004-6-21 22:34:00 | 只看该作者
谢谢!跟chenzirong学了一招![em07]
8#
 楼主| 发表于 2004-7-9 19:31:00 | 只看该作者
不错,能作到就好。,。
9#
发表于 2004-7-22 18:18:00 | 只看该作者
要的就是它!太感谢了!
10#
发表于 2004-7-29 22:40:00 | 只看该作者
好像可以用WINSOCK或EZFTP控件的,我没用过,但应该比WINAPI好写
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-1 09:21 , Processed in 0.089934 second(s), 35 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表