python paramiko:权限被拒绝

时间:2011-08-10 18:24:10

标签: python sftp paramiko permission-denied

我有一个名为transmit的sftp程序。我用它来访问sftp服务器。我用用户名,密码登录,一切正常。我可以删除,创建和查看所有内容。

现在我必须使用python脚本访问这个sftp服务器。因此我安装了parmiko。我在演示文件中设置了所有内容,但是我扼要地得到了错误消息:允许拒绝:

hostname = "123.456.789.1"
port = 22

hostkeytype = None
hostkey = None
try:
    host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
except IOError:
    print '*** Unable to open host keys file'
    host_keys = {}

if host_keys.has_key(hostname):
    hostkeytype = host_keys[hostname].keys()[0]
    hostkey = host_keys[hostname][hostkeytype]
    print 'Using host key of type %s' % hostkeytype

t = paramiko.Transport( (hostname, port) )
t.connect( username="customUser", password="xyzpasswd", hostkey=hostkey, pkey=None )
sftp = paramiko.SFTPClient.from_transport(t)
print sftp.listdir() # <- works
sftp.get("~/myfolder/test.png",".", None ) # <- permission denied error
t.close()

如果我运行它,这就是输出:

Using host key of type ssh-dss
['.ssh2', 'archiv', 'myfolder']
Traceback (most recent call last):
File "/path/to/myscript.py", line 539, in <module>
main()   
File "/path/to/myscript.py", line 531, in main
ladeDatenVomSFTPServer()   
File "/path/to/myscript.py", line 493, in ladeDatenVomSFTPServer
sftp.get("~/myfolder/test.png",".", None )
File "build/bdist.macosx-10.6-intel/egg/paramiko/sftp_client.py", line 606, in get
File "build/bdist.macosx-10.6-intel/egg/paramiko/sftp_client.py", line 245, in open
File "build/bdist.macosx-10.6-intel/egg/paramiko/sftp_client.py", line 635, in _request
File "build/bdist.macosx-10.6-intel/egg/paramiko/sftp_client.py", line 682, in _read_response
File "build/bdist.macosx-10.6-intel/egg/paramiko/sftp_client.py", line 712, in _convert_status
IOError: Permission denied, file: ~/myfolder/test.png

这一切在传输中工作正常但是parmiko失败了。我错了什么?

1 个答案:

答案 0 :(得分:0)

我认为第二个参数应该是文件名,而不是点.

替换

sftp.get("~/myfolder/test.png",".", None )

类似

sftp.get("~/myfolder/test.png","~/test.png", None )