来自MS Access的FTP? [英] FTP from MS Access?

查看:40
本文介绍了来自MS Access的FTP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过VBA(或内置的访问控制)将一个FTP连接到一个网站?示例

所需的功能将是:文件上传,下载,删除,重命名,移动,

和导演列表。


在此先感谢

How can one FTP to one''s site via VBA (or built in Access control)? Examples
of required funtions would be: file upload, download, delete, rename, move,
and director listing.

Thanks in advance

推荐答案

这就是我使用的:


选项比较数据库

选项明确

私有Const ModEro = 9100

公共功能FTP(ascii As Boolean,send As Boolean,pathname As String,

FileName As String,server As String,serverpathname As String,

RstN As String,optional RstFld As String)

Dim Fs As Object

Dim a As Variant

Dim RST As Recordset

Const脚本=" __ temp_script.tmp"

''---

Dim asciiType As String

如果ascii = True那么asciiType =" ascii" ;否则asciiType =" binary"

''---

Dim SendType As String

如果send = True则SendType =" Put " Else SendType =" Get"

''---创建并打开文件

设置Fs = CreateObject(" Scripting.FileSystemObject")

设置a = Fs.CreateTextFile(路径名&" \"& script,True)

''将所有行写入文件

a.writelinelcd &安培; Chr(34)&路径名称& Chr(34)

a.writeline" open" &安培;服务器

a.writeline用户名

a.writeline密码

如果(serverpathname<>"")那么a.writeline" ; cd &安培; serverpathname

if(ascii)那么

a.writeline asciiType

否则

a.writeline asciiType

结束如果

如果RstN<> ""然后

设置RST = CurrentDb.OpenRecordset(RstN)

做的不是RST.EOF

FileName = RST.Fields(RstFld)& " .html"

serverfilename = FileName

a.writeline SendType& FileName& " " &安培; serverfilename

RST.MoveNext

Loop

Else

a.writeline SendType& FileName& " " &安培; serverfilename

结束如果

a.writeline" bye"

''关闭文件

a.Close < br $>
sFTP(路径名&" \"&脚本)

结束功能


私有子sFTP(stSCRFile As String)

Dim stSysDir As String

''---

stSysDir = Environ
This is what I use:

Option Compare Database
Option Explicit
Private Const ModEro = 9100

Public Function FTP(ascii As Boolean, send As Boolean, pathname As String,
FileName As String, server As String, serverpathname As String,
serverfilename As String, username As String, password As String, Optional
RstN As String, Optional RstFld As String)
Dim Fs As Object
Dim a As Variant
Dim RST As Recordset
Const script = "__temp_script.tmp"
''---
Dim asciiType As String
If ascii = True Then asciiType = "ascii" Else asciiType = "binary"
''---
Dim SendType As String
If send = True Then SendType = "Put " Else SendType = "Get "
''---create and open the file
Set Fs = CreateObject("Scripting.FileSystemObject")
Set a = Fs.CreateTextFile(pathname & "\" & script, True)
'' write all the lines to the file
a.writeline "lcd " & Chr(34) & pathname & Chr(34)
a.writeline "open " & server
a.writeline username
a.writeline password
If (serverpathname <> "") Then a.writeline "cd " & serverpathname
If (ascii) Then
a.writeline asciiType
Else
a.writeline asciiType
End If
If RstN <> "" Then
Set RST = CurrentDb.OpenRecordset(RstN)
Do While Not RST.EOF
FileName = RST.Fields(RstFld) & ".html"
serverfilename = FileName
a.writeline SendType & FileName & " " & serverfilename
RST.MoveNext
Loop
Else
a.writeline SendType & FileName & " " & serverfilename
End If
a.writeline "bye"
''close file
a.Close
sFTP (pathname & "\" & script)
End Function

Private Sub sFTP(stSCRFile As String)
Dim stSysDir As String
''---
stSysDir = Environ


( COMSPEC)

stSysDir =左
("COMSPEC")
stSysDir = Left


(stSysDir,Len(stSysDir) - Len(Dir(stSysDir)))

调用Shell(stSysDir&" ftp.exe -s:"& stSCRFile,vbNormalFocus)

End Sub

(stSysDir, Len(stSysDir) - Len(Dir(stSysDir)))
Call Shell(stSysDir & "ftp.exe -s:" & stSCRFile, vbNormalFocus)
End Sub


这篇关于来自MS Access的FTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆