使用 VBA 上传 SFTP [英] SFTP upload with VBA

查看:126
本文介绍了使用 VBA 上传 SFTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够通过 VBA 进行 SFTP.我有一个 Access 程序可以提取数据并对其进行操作,现在我必须找到一种方法通过 SFTP 上传 excel 07 文件.

i need to be able to SFTP though VBA. I have an Access program that pulls data, manipulates it and now i have to find a way to upload the excel 07 file through SFTP.

我在网上找了好几天,什么也找不到.我在这里看到了一个类似的话题 How to use sftp来自 MS Access 数据库模块?,我很想找到 Mat Nadrofsky,因为他似乎有一个解决方案,我只是无法理解其中任何一个))))))))))))

i've been looking on the net for days and can't find anything. I saw a similar topic here How to use sftp from within an MS Access database module?, and i'd love to find Mat Nadrofsky, because it seemed like he has a solution, i just cant understand any of it)))))))))))

所以如果有人可以解释该解决方案是关于什么或有不同的解决方案 - 我真的很感激谢谢

so if someone can explain what that solution was about or has a different solution - i'd really appreciate it thank you

推荐答案

在您链接的上一个 SO 答案中,Mat Nadrofsky 使用了 sftp 命令行客户端.在这个例子中,我的 sftp 客户端是 pscp.exe.该客户端是 PuTTY 工具的一部分:PuTTY 下载页面

In the previous SO answer you linked, Mat Nadrofsky used an sftp command line client. In this example my sftp client is pscp.exe. That client is part of the PuTTY tools: PuTTY Download Page

我想构建并运行这样的命令来将 sample.txt 复制到我在远程机器上的主目录:

I want to build and run a command like this to copy sample.txt to my home directory on the remote machine:

"C:\Program Files\PuTTY\pscp.exe" -sftp -l hans -pw changeme C:\Access\sample.txt 192.168.1.6:/home/hans/

因此此过程将构建并运行该命令字符串.

So this procedure will build and run that command string.

Public Sub SftpPut()
    Const cstrSftp As String = """C:\Program Files\PuTTY\pscp.exe"""
    Dim strCommand As String
    Dim pUser As String
    Dim pPass As String
    Dim pHost As String
    Dim pFile As String
    Dim pRemotePath As String

    pUser = "hans"
    pPass = "changeme"
    pHost = "192.168.1.6"
    pFile = "C:\Access\sample.txt"
    pRemotePath = "/home/hans/"

    strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
        " " & pFile & " " & pHost & ":" & pRemotePath
    Debug.Print strCommand
    Shell strCommand, 1 ' vbNormalFocus '
End Sub

您可能更喜欢 ShellAndWait 而不是 Shell,正如 David Fenton 在评论上一个答案.

You may prefer ShellAndWait instead of Shell, as David Fenton suggested in a comment on the previous answer.

这篇关于使用 VBA 上传 SFTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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