Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA Excel和Putty(FTP)-等待调用外壳和旁路主机项未缓存在注册表中_Excel_Vba_Ftp_Putty - Fatal编程技术网

VBA Excel和Putty(FTP)-等待调用外壳和旁路主机项未缓存在注册表中

VBA Excel和Putty(FTP)-等待调用外壳和旁路主机项未缓存在注册表中,excel,vba,ftp,putty,Excel,Vba,Ftp,Putty,我的excel文件中有一个宏,它使用pscp(putty客户端)将文件上载到我的服务器 这是密码 Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim waitOnReturn As Boolean: waitOnReturn = True Dim windowStyle As Integer: windowStyle = 1 Dim cstrSftp As String Dim strCommand As Stri

我的excel文件中有一个宏,它使用pscp(putty客户端)将文件上载到我的服务器

这是密码

Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

Dim cstrSftp As String
Dim strCommand As String
Dim pUser As String
Dim pPass As String
Dim pHost As String
Dim pFile As String
Dim pRemotePath As String

'Specifying the values
cstrSftp = """" & Application.ActiveWorkbook.Path & "\pscp.exe" & """"
pUser = "username"
pPass = "password  "
pHost = "ftp.xyz.com"
pFile = """" & Application.ActiveWorkbook.Path & "\test.mkv" & """"
pRemotePath = "/home/storage/public_html/"

'Setting the command
strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
    " " & pFile & " " & pHost & ":" & pRemotePath

'Execution
 wsh.Run strCommand, windowStyle, waitOnReturn
这很好,但我有两个问题:

1) 使用Windows 10,系统会弹出一条消息,询问用户是否要运行pscp.exe。我想绕过这一点

我使用的不是WScript.Shell,而是:

Call Shell(strCommand, vbNormalFocus)
使用Call Shell操作系统不会询问运行pscp.exe,但问题是我无法知道进程何时结束

2) 当用户第一次运行该命令时,putty将提示以下消息:

服务器的主机密钥未缓存在注册表中。你没有 确保服务器是您认为的计算机。这个 服务器的rsa2密钥>指纹是:[ssh rsa 1024 somekey] 信任此主机,输入“y”将密钥添加到PuTTY的缓存和携带中 关于连接。如果您只想继续连接一次,而不需要 将密钥添加到缓存中,输入“n”。如果您不信任此主机, 按Return放弃连接。在缓存中存储密钥?(是/否)

我需要它是完全即时免费的,自动的

我试着这样使用“echo n”:

strCommand=“echo n |”&cstrSftp&&sftp-l&pUser&&pw&pPass&_ &pFile&&pHost&:&pRemotePath

但是我得到的信息是“IWshShell3”失败了。

问题2解决了

Echo是一个批处理文件命令,因此它需要一个包装器

此命令可用于:

strCommand=“cmd/c echo n|”&cstrSftp&&sftp-l&pUser&&pw&pPass&_
&pFile&&pHost&:“&pRemotePath

永远不要这样做!提示出现是有原因的。必须验证主机密钥。这是两个独立的问题。因此,请分别询问他们。