這裏我使用telnet在遠程主機上建立一個連接,然後在遠程主機上創建一個名爲「file.txt」的文件並存儲結果在file.txt中執行「ls」命令。現在我需要將文件發送到本地主機。我不知道該怎麼做。任何知道它的人都會幫助我。如何通過使用tcl-expect將遠程主機上的文件複製到本地主機
#!/usr/local/bin/expect
spawn telnet <machine ip>
expect "login:"
send "<username>\n"
expect "Password:"
send "<password>\n"
expect "bash"
send " ls > file.txt\r "
expect "bash"
send " cat file.txt \r "
expect "bash"
send " command for copying file to the localhost computer\r"
expect "bash"
send "exit\r"
一個強制性的評論:你真的不能使用SSH來做到這一點原生? – kostix
我不知道ssh。 – deva
好的時候去了解它,真的。請參閱Donal的答案後的評論主題了解更多信息。 – kostix