Access开发平台--上传下载函数,实现通用附件支持FTP。-丘苏洲
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access开发平台


Access开发平台--上传下载函数,实现通用附件支持FTP。

发表时间:2019/4/17 0:52:35 评论(2) 浏览(9137)  评论 | 加入收藏 | 复制
   
摘 要:开发平台上传下载函数,实现通用附件支持FTP。
正 文:

      Access快速开发平台通用附件的图片用共享文件夹的方式,安全性能不高,可能存在误删除。把图片文件用FTP的方法保存,在客户端开通FTP即可实现通用附件的FTP网络服务器实时共享。

优点是括大了服务器的应用范围,缺点是每次浏览都要重新下载更新图片文件,性能不如共享。

一、企业版:设置开发平台FTP:

专业版在系统表 Sys_ServerParameters 手工增加以下内容即可。


二、复制上传,下载自定义函数代码到“模块”


三、在 通用附件窗体(SysFrmAttachments) 下新增红字调用函数代码:

代码所在位置请自行对应。


四、架设FTP服务器方法请自行查找。

1、保存事件

Public Function SaveAttachmentData(DataCategory As String _
                                 , DataID As Variant _
                                 , Optional ActiveConnection As Variant _
                                   )

‘中间部分省略
        rst![AttachmentName] = rstTmp![AttachmentName]
        uploadFTPfile rstTmp![AttachmentName] '上传到FTP
        rst.Update
中间部分省略


2、加载浏览事件

Public Function LoadAttachmentData(DataCategory As String _
                                 , DataID As Variant _
                                 , Optional ActiveConnection As Variant _
                                  )
中间部分省略

        rstTmp![AttachmentName] = rst![AttachmentName]

        downloadFTPfile rst![AttachmentName] '下载FTP到本地
        rstTmp.Update
中间部分省略


附上传及下载函数:

Function downloadFTPfile(downFILEname As String) As Boolean
    On Error GoTo ErrorHandler
    '下载 FTP 文件
    If getParameter("FTP Server Address", dbText, "", , , True) = "" Then GoTo ExitHere
    Dim AttPATH As String
    '本地保存路径设置
    AttPATH = getParameter("Attachment Path", dbText, "", , , True)
    If Len(AttPATH) = 0 Then AttPATH = CurrentProject.Path & "\Attachments\"
    If Left(AttPATH, 2) = ".\" Then AttPATH = CurrentProject.Path & Mid(AttPATH, 2)
    If Right(AttPATH, 1) <> "\" Then AttPATH = AttPATH & "\" 

  If dir(AttPATH)="" then mkdir(AttPATH)  

  With FTPServer
        .OpenConnection ‘专业版需直接使用参数 getParameter("FTP Server Address", dbText, "", , , True),getParameter("FTP Server Port", dbText, "", , , True),getParameter("FTP Server Username", dbText, "", , , True),getParameter("FTP Server Password", dbText, "", , , True)

        If .FileExists("Attachments\" & downFILEname) Then .DownloadFile "Attachments\" & downFILEname, AttPATH & downFILEname
        .CloseConnection
    End With
ExitHere:
    downloadFTPfile = True
    Exit Function
    
ErrorHandler:
    downloadFTPfile = False
End Function
Function uploadFTPfile(upFILEname As String) As Boolean
    On Error GoTo ErrorHandler
    '上传 FTP 文件
    If getParameter("FTP Server Address", dbText, "", , , True) = "" Then GoTo ExitHere
    Dim AttPATH As String
    '本地保存路径设置
    AttPATH = getParameter("Attachment Path", dbText, "", , , True)
    If Len(AttPATH) = 0 Then AttPATH = CurrentProject.Path & "\Attachments\"
    If Left(AttPATH, 2) = ".\" Then AttPATH = CurrentProject.Path & Mid(AttPATH, 2)
    If Right(AttPATH, 1) <> "\" Then AttPATH = AttPATH & "\"
    
    With FTPServer
        .OpenConnection ‘专业版需直接使用参数 getParameter("FTP Server Address", dbText, "", , , True),getParameter("FTP Server Port", dbText, "", , , True),getParameter("FTP Server Username", dbText, "", , , True),getParameter("FTP Server Password", dbText, "", , , True)
        '判断FTP是否存在Attachments文件夹
        If .FileExists("Attachments") = False Then .CreateDirectory "Attachments"
        If Dir(AttPATH & upFILEname) <> "" Then .UploadFile AttPATH & upFILEname, "Attachments\" & upFILEname
        .CloseConnection
    End With
ExitHere:
    uploadFTPfile = True
    Exit Function
    
ErrorHandler:
    uploadFTPfile = False
End Function


Access软件网交流QQ群(群号:198465573)
 
 相关文章
FTP上传下载  【一杯绿茶  2014/4/15】
Access开发平台--让通用附件模块支持ftp  【宽一  2016/4/25】
Access开发平台--FTP文件共享处理/互联网实现附件上传下载...  【杜超  2016/10/10】
FTP、sqlsever外网访问端口映射设置  【凝听  2017/11/2】
怎样开通FTP功能  【杨雪  2017/12/5】
从FTP下载文件并覆盖到当前文件夹的main文件  【凝听  2017/12/15】
Access快速开发平台--使用FTP管理档案  【lmqlt  2019/1/19】
常见问答
技术分类
相关资源
文章搜索
关于作者

丘苏洲

文章分类

文章存档

友情链接