Office中国论坛/Access中国论坛

标题: [新4]用ACCESS向ftp服务器上传文件 [打印本页]

作者: jzwwpp    时间: 2004-3-2 00:35
标题: [新4]用ACCESS向ftp服务器上传文件
不调用任何ftp软件,只使用ACCESS编程实现。。。
作者: jzwwpp    时间: 2004-3-2 00:37
我想是否可以调用web浏览器直接打开ftp,然后复制所需文件,再粘贴到web浏览器,现在只能想到这样了,不知高手门有没有更好的办法。
作者: jzwwpp    时间: 2004-3-2 22:16
另外一个做法:
直接用一个ole连接字段,然后把文件存进去。在界面上作个按钮,用代码插入ole连接对象,看起来就像上传一样,这样唯一的缺点就是数据库增大的很快,只能定期维护,我的解决的办法就是作一个按钮“查看”,打开文件的同时就将这个对象删除,以减小数据库的尺寸。请问那位有更好的办法???
作者: CHENZHIRONG    时间: 2004-6-11 16:39
用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
作者: fremgo    时间: 2004-6-11 21:46
晕, 这不把FTP软件的FTP代码都般过来了吗, hoho~
作者: lwwvb    时间: 2004-6-19 21:03
做到了题目就OK啦!为什么要介意这个?这种题目就好象说:我要你走路,但不准用脚走![em11]
作者: DC10    时间: 2004-6-21 22:34
谢谢!跟chenzirong学了一招![em07]
作者: jzwwpp    时间: 2004-7-9 19:31
不错,能作到就好。,。
作者: MosesCao    时间: 2004-7-22 18:18
要的就是它!太感谢了!
作者: fresh+men    时间: 2004-7-29 22:40
好像可以用WINSOCK或EZFTP控件的,我没用过,但应该比WINAPI好写
作者: milerzhang    时间: 2005-5-12 18:09
有没有更好的方法!!!
作者: paltt    时间: 2006-3-9 17:50
高手啊。。。。。。。
作者: guoya    时间: 2006-4-17 02:20
可以使用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

作者: kaka022    时间: 2009-7-14 11:35
EZFTP控件?
作者: xjb_test    时间: 2009-7-14 22:12
学习一下
作者: gdjdyyj    时间: 2014-4-17 21:46
学习
作者: llm4947    时间: 2015-1-9 20:29
不错




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3