目前我在 Excel vba 中工作。我对此了解不多。
我正在使用 putty sftp 命令进行文件传输操作,我正在使用下面的代码。我还在我的电脑上安装了winscp & putty。
我的代码是:
Dim shell As Object
Dim command As String
Dim errorCode As Integer
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 0
Set shell = VBA.CreateObject("WScript.Shell")
command = "cmd.exe /c echo y |"C:\Program Files (x86)\PuTTY\pscp.exe"
-sftp -P 22 -l Username_Here -pw Password_Here
SRC_IP_Address_Here:File_Path_Here " " Destination_Path_Here
' error code is 0 if all ok otherwise 1
errorCode = shell.Run(command, windowStyle, waitOnReturn)
如果存在 ip 地址和目标路径,则上面的代码可以正常工作,但如果在网络中无法访问 ip 地址,则 excel 需要 20-30 秒才能响应且 errorCode = 1。
是否可以修改上述代码,使其仅在 10 秒内给我响应?
如何在上面的代码中设置 putty sftp 连接超时?
我尝试了以下链接,但没有得到任何结果:
https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/
https://www.computerhope.com/unix/sftp.htm
https://library.netapp.com/ecmdocs/ECMP1196993/html/GUID-02FF883B-9913-4137-BC8B-5CB47282B944.html
https://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter5.html