免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 12849 | 回复: 3

paramiko浅涉 [复制链接]

论坛徽章:
0
发表于 2008-05-20 16:25 |显示全部楼层

                号称支持ssh2的,怎么着都比expect要安心点。那个api的文档看着真吃力,幸好提供了一些demo的脚本参考;
安装
前提需要安装pycrypt模块,均为标安,install即可,最后可运行test.py进行检测;
下面就该摸索了--(粗浅之极,不排除有错误之处)
看到1个transport,1个channel,ms channel可用select对transport进行选择,还没摸(默。。)
transport用来建立ssh链接;
channel则是对于这个链接的相关设置;
testssh=paramiko.transport.init(sock)-- 建立一个ssh的端口连接,sock=(host,port);
密码连接,利用transport的connect方法:
testssh.connect(username=hostname,password=password)
俺是打算传文件的,所以用sftpclient这个模块,
sftpclient的init说是要用channel已存在的连接,但还提供一个直接用transport产生的链接:
sftptest=paramiko.sftpclient.from_transport(testssh)
使用了这个类,就可以传文件了:
sftptest.put(localfile,remotefile)
需要说明下的是,remotefile必须写出整个file的名称,不能写目录名;还有这个put方法只能上传文件,不能传目录的,不知道这个paramiko有没直接传目录的方法的,但是在sftpclient下面是有mkdir这样的方法;
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/57278/showart_695988.html

论坛徽章:
0
发表于 2011-06-21 15:16 |显示全部楼层
谢谢,学习了。

论坛徽章:
0
发表于 2011-06-21 15:30 |显示全部楼层
sock.connect((HOST,PORT))
t = paramiko.Transport(sock)
t.start_client()
t.auth_password(USERNAME,PASSWORD)

sftptest=paramiko.SFTPClient.from_transport(t)
sftptest.get(remotefile,localpath)

我这样子提示:下载到本地没权限啊。郁闷。。怎么弄。
Traceback (most recent call last):
  File "D:/我的文档/python/getfile.py", line 24, in <module>
    sftptest.get(remotefile,localpath)
  File "build\bdist.win32\egg\paramiko\sftp_client.py", line 610, in get
    fl = file(localpath, 'wb')
IOError: [Errno 13] Permission denied: 'D:\\docs'
>>>

论坛徽章:
0
发表于 2011-11-23 13:45 |显示全部楼层
回复 3# zhengsenlin888


     拿 administrator 来跑啊  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP