免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 8280 | 回复: 26
打印 上一主题 下一主题

请教如何用PERL执行SSH命令? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-29 00:12 |只看该作者 |倒序浏览
各位, 请帮我看看下面用来连F-Secure SSH server的代码为什么不成功?
环境:  WinXP + ActivePerl5.8.7 Build813

use Net::SSH::W32Perl;

%params = ("debug",true);

$ssh = Net::SSH::W32Perl->new("192.168.0.168",%params, protocol=>2);
print "Start to login to remote SSH server...\n";
$ssh->login("ray","*ik,9ol.",1);
print "Login succeed!\n";
print "Begin to run remote command...\n";
print $ssh->cmd( 'ls -lA > ls.txt' );

运行之后, 如下显示:
gameplace: Reading configuration data C:\Documents and Settings\Ray/.ssh/config
gameplace: Reading configuration data /etc/ssh_config
gameplace: Connecting to 192.168.0.168, port 22.
gameplace: Socket created, turning on blocking...
gameplace: Remote version string: SSH-2.0-3.2.3 F-Secure SSH Windows NT Server


gameplace: Remote protocol version 2.0, remote software version 3.2.3 F-Secure SSH Windows NT Server

gameplace: Net::SSH:erl Version 1.30, protocol version 2.0.
gameplace: No compat match: 3.2.3 F-Secure SSH Windows NT Server
.
gameplace: Connection established.
gameplace: Sent key-exchange init (KEXINIT), wait response.
gameplace: Algorithms, c->s: 3des-cbc hmac-sha1 none
gameplace: Algorithms, s->c: 3des-cbc hmac-sha1 none
gameplace: Entering Diffie-Hellman Group 1 key exchange.
gameplace: Sent DH public key, waiting for reply.
gameplace: Received host key, type 'ssh-dss'.
gameplace: Host '192.168.0.168' is known and matches the host key.
gameplace: Computing shared secret key.
gameplace: Verifying server signature.
gameplace: Waiting for NEWKEYS message.
gameplace: Enabling incoming encryption/MAC/compression.
gameplace: Send NEWKEYS, enable outgoing encryption/MAC/compression.
gameplace: Sending request for user-authentication service.
gameplace: Service accepted: ssh-userauth.
gameplace: Trying empty user-authentication request.
gameplace: Authentication methods that can continue: publickey,password.
gameplace: Next method to try is publickey.
gameplace: Next method to try is password.
gameplace: Trying password authentication.
gameplace: channel 0: new [client-session]
gameplace: Requesting channel_open for channel 0.
gameplace: Entering interactive session.
Start to login to remote SSH server...
Login succeed!
Begin to run remote command...
gameplace: Sending command: ls -lA > ls.txt
gameplace: Requesting service exec on channel 0.
gameplace: channel 0: open confirm rwindow 100000 rmax 16384


然后就永远没下文了.
那位给看看啊 .
感激不尽!

论坛徽章:
0
2 [报告]
发表于 2006-11-29 09:33 |只看该作者

自己顶住!

过路的兄弟/姐妹, 给点建议也好......
感激的一塌糊涂......

论坛徽章:
0
3 [报告]
发表于 2006-11-29 11:15 |只看该作者
感觉print $ssh->cmd( 'ls -lA > ls.txt' );
比较奇怪。

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2006-11-29 11:51 |只看该作者
ls.txt打开看看...

论坛徽章:
0
5 [报告]
发表于 2006-11-29 12:55 |只看该作者

谢谢帮忙.

这个ls命令根本没有执行.
也没有产生ls.txt文件.

论坛徽章:
0
6 [报告]
发表于 2006-11-29 13:24 |只看该作者
我这里试验的是没有什么问题的,只是这个模块相当的慢,好几次我都以为死在那里了,但实际上还是在跑的。

不如你多等等?

论坛徽章:
0
7 [报告]
发表于 2006-11-29 14:15 |只看该作者

我已经等了好几天了

呵呵, 夸张了点,其实好几十分钟了.

论坛徽章:
0
8 [报告]
发表于 2006-11-29 16:21 |只看该作者
原帖由 Flying168168 于 2006-11-29 14:15 发表
呵呵, 夸张了点,其实好几十分钟了.

太夸张了,几十分钟
换别的模块试试看

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
9 [报告]
发表于 2006-11-29 17:16 |只看该作者
gameplace: Remote version string: SSH-2.0-3.2.3 F-Secure SSH Windows NT Server

1.windows NT上有 ls吗?
   缺省应该没有吧!!
2.NT的ssh你要check一下..我记得NT的telnet server传回来的都是一堆控制码...ssh server我就不晓得
3.Windows上可以redirect stdout吗?
  我记得是不行的喔..

[ 本帖最后由 apile 于 2006-11-29 17:22 编辑 ]

论坛徽章:
0
10 [报告]
发表于 2006-11-29 23:35 |只看该作者
我装了MKS TOOLS,所以可在NT上用ls 命令.
这个问题查GOOGLE也没什么结果.郁闷.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP