问题 - 将 key 存储在缓存中问题停止 VBA 应用程序
我使用 pscp.exe 将文件从 Windows 传输到 Linux 机器。
备注:pscp.exe存在于我的VBA代码中(该客户端是PuTTY工具的一部分)
当我将文件从我的 PC 复制到任何新的 Linux 机器时,我收到“将密钥存储在缓存中?(是/否)”的问题,这会中断我的 VBA 应用程序(VBA 应用程序在 sftp 进程上停止)。
我需要建议如何忽略“将 key 存储在缓存中?(是/否)”这个问题。或者从我的 VBA 代码中自动发送一个“y”键?或者在运行 pscp.exe 之前在 PC 注册表中定义的其他解决方案?但是该怎么做呢?
来自 WIN XP 命令行 (cmd) 的示例
备注:192.9.200.120(Linux服务器IP地址)
"D:\documents and settings\udavid\pscp.exe" -sftp -l root -pw pass123 "D:\Documents and Settings\udavid\Desktop\scan_ip.ksh" 192.9.200.120:/var/tmp
命令输出:
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 1024 15:e1:ce:4f:8e:4e:7b:61:14:c3:df:3c:b1:50:67:b6
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
如果我使用 -batch 标志 (pscp.exe -batch),CMD 输出示例
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 d5:80:49:7f:69:f1:29:7c:1f:99:ec:c9:f4:b2:6f:a0
Connection abandoned.
Lost connection
--- Example from my VBA code ---
Const cstrSftp As String = """D:\documents and settings\udavid\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 = "root"
pPass = "pass123"
pHost = "xxx.xxx.xxx.xxx" xxx.xxx.xxx.xxx - any server new IP
pFile = """D:\Documents and Settings\udavid\Desktop\scan_ip.ksh"""
pRemotePath = "/var/tmp"
strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & " " & pFile & " " & pHost & ":" & pRemotePath
Debug.Print strCommand
Shell strCommand, 1
最佳答案
您可以使用 Shell "cmd/c echo y | "& strCommand, 1
作为建议的快速破解。
我用自制的cExec类来管道输出并有选择地响应像这样的腻子警告
With New cExec
.Run "d:\downloads\pscp.exe", sParams, True
Do While Not .AtEndOfOutput
If InStr(.ReadLineOutput, "(y/n)") Then
.WriteInput "y"
End If
Loop
End With
关于windows - 从 VBA 代码调用 SFTP 进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8701871/