如何使用 tcl-expect 将文件从远程主机复制到本地主机
在这里,我使用 telnet 在两台机器之间建立连接,并在远程主机中创建一个名为“file.txt”的文件,并将“ls”命令执行的结果存储在 file.txt 中。现在我需要将文件发送到本地主机。我不知道该怎么做。任何知道的人都请帮助我。
#!/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"
Here i am making a connection b/w two machines using telnet and in the remote host i am creating a file named "file.txt" and storing the result of the "ls" command execution in the file.txt. now i need to send the file to the local host. i dont know how to do it. anybody who knows it kindly help me out here.
#!/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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
强烈建议您使用
ssh
和scp
来执行此任务。You're strongly recommended to use
ssh
andscp
for this task.