设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 9471|回复: 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
17#
发表于 2015-1-9 20:29:16 | 只看该作者
不错
回复

使用道具 举报

16#
发表于 2014-4-17 21:46:40 | 只看该作者
学习
回复

使用道具 举报

15#
发表于 2009-7-14 22:12:23 | 只看该作者
学习一下
14#
发表于 2009-7-14 11:35:51 | 只看该作者
EZFTP控件?
13#
发表于 2006-4-17 02:20:00 | 只看该作者
可以使用Catalyst File Transfer Control 4.0 (SP3)控件

Private Sub Command6_Click() '上传
Dim strLocalFullName As String
Dim strRemoteFullName As String
Dim lResult As Long

strLocalFullName = Me.TxtLocalName
strRemoteFullName = FullName(TxtRemoteFolder, TxtRemoteFileName)

    FileTransfer2.ServerType = GetServerType
    FileTransfer2.ServerName = Me.TxtSeverName
    FileTransfer2.ServerPort = 21
    '以下根据需要决定
    'FileTransfer2.Timeout = CLng(Val(editTimeout.Text))
    'FileTransfer2.UserName = Trim(editUserName.Text)
    'FileTransfer2.Password = Trim(editPassword.Text)
    lResult = FileTransfer2.Connect
    If lResult <> 0 Then
            MsgBox "Connection failed" & vbCrLf & FileTransfer21.LastErrorString
    End If
   
lResult = FileTransfer2.PutFile(strLocalFullName, strRemoteFullName)

If lResult <> 0 Then
            MsgBox "Transfer failed" & vbCrLf & FileTransfer2.LastErrorString
End If

lResult = FileTransfer2.Disconnect
End Sub


Private Function FullName(strDir As String, strFile As String) As String
Dim strDelim As String
Dim strLastChar As String

    strDelim = "\"
    If InStr(strDir, "/") > 0 Then strDelim = "/"
    strLastChar = Right(strDir, 1)
    If strLastChar = strDelim Then
        FullName = strDir & strFile
    Else
        FullName = strDir & strDelim & strFile
    End If
End Function
12#
发表于 2006-3-9 17:50:00 | 只看该作者
高手啊。。。。。。。
11#
发表于 2005-5-12 18:09:00 | 只看该作者
有没有更好的方法!!!
10#
发表于 2004-7-29 22:40:00 | 只看该作者
好像可以用WINSOCK或EZFTP控件的,我没用过,但应该比WINAPI好写
9#
发表于 2004-7-22 18:18:00 | 只看该作者
要的就是它!太感谢了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 07:27 , Processed in 0.104178 second(s), 36 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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