Excel 捕获WScript Shell对象的输出

Excel 捕获WScript Shell对象的输出,excel,ftp,putty,vba,Excel,Ftp,Putty,Vba,此代码使用Putty将文件上载到FTP服务器 Dim wsh As Object Dim waitOnReturn As Boolean Dim windowStyle As Integer 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

此代码使用Putty将文件上载到FTP服务器

Dim wsh As Object
Dim waitOnReturn As Boolean
Dim windowStyle As Integer
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
Dim site As String
Dim resp As String

Set wsh = VBA.CreateObject("WScript.Shell")

'Wait the execution to finish
waitOnReturn = True

'Show the window
windowStyle = 1

'Variables
cstrSftp = """" & Application.ActiveWorkbook.Path & "\pscp.exe" & """"
site = "http://mysite/"
pUser = "user"
pPass = "password  "
pHost = "ftp.mysite"
pRemotePath = "/home/"
pFile = """" & Application.ActiveWorkbook.Path & "file.png" & """"

'Command string
strCommand = "cmd /c echo n | " & cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & " " & pFile & " " & pHost & ":" & pRemotePath

'Run the command
wsh.Run strCommand, windowStyle, waitOnReturn
由于存储服务器不可靠,我需要捕获输出以了解上传是否有效。如果没有,我需要知道那是什么信息

我想使用命令“>C:\output.txt”来捕获输出。像这样

strCommand = strCommand & " > " & """" "C:\output.txt" & """"
当上传工作时,我的输出文件也工作。但是,当上传不起作用时,输出文件中不会写入任何内容


例如,当我收到消息
Fatal:Server意外关闭网络连接时
输出文件中没有写入任何内容。但我需要知道给出的确切消息是什么。

使用exec检索输出的示例,也许这对您的情况很有用

Sub TestExec()

Dim wsh As New WshShell
Dim s As String

    s = wsh.Exec("cmd /c Dir C:\ ").StdOut.ReadAll
    Debug.Print s

End Sub

你以前不是问过同样的问题吗?我建议使用exec。@Storax exec?你能再详细一点吗?