2011-03-17 260 views
5

我有一个做FTP的VBA库,我也想做telnet。目前,我正在向一个基于文本文件的telnet执行Perl脚本,但我想从VBA中本地驱动telnet连接。有没有人有任何来源?我不想使用加载项,我需要代码是独立的。从VBA运行Telnet会话

+1

问代码通常不会在这里工作。您如何向我们展示您所做的事情,我们将帮助您实现目标或使其变得更好。另外,如果您参考Perl脚本和VBA FTP库,这将会很有帮助。 – Abbas 2011-03-17 10:11:32

+0

同意,这就是我回答它的原因。但通常会有更多的细节。 – Abbas 2011-03-17 11:28:53

+0

感谢您的回复。我现有的VBA FTP代码在这里:http://www.eggheadcafe.com/software/aspnet/35435157/ftp-file-size-from-wininet.aspx – PhilHibbs 2011-03-29 09:29:58

回答

0

如果你能use the MS WinSock control(见using winsock in VBA

更多资源:

MSDN Library: Using the Winsock Control

(Visual Basic) Winsock Control

如果没有,你可以使用CMD.EXESendKeys也许是:

免责声明:我从下面的链接中复制了下面的代码,并稍微修改了VBA的代码。

sub telNETScript() 
On Error Resume Next 
Dim WshShell as object 

set WshShell=CreateObject("WScript.Shell") 
WshShell.run "cmd.exe" 
WScript.Sleep 1000 

'Send commands to the window as needed - IP and commands need to be customized 
'Step 1 - Telnet to remote IP' 
WshShell.SendKeys "telnet xx.xx.xx.73 9999" 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 

'Step 2 - Issue Commands with pauses' 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
WshShell.SendKeys "5" 
WshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 

'Step 3 - Exit Command Window 
WshShell.SendKeys "exit" 
WshShell.SendKeys ("{Enter}") 
WScript.Quit 

end sub 

SendKeys是不是最好的或最可靠的解决方案,但它是所有我12年前在我的上一份工作做了这个时候,我能找到。

更多信息:

Telnet & Excel - Microsoft.excel.programming

How to automate Telnet commands using VBScript