2011-08-10 188 views
0

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

现在我必须用python脚本访问这个sftp服务器。所以我安装了parmiko。我设立了一切,在演示文件,但我strangly得到否定的错误信息在未经许可的:

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

你是如何运行脚本替换

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

? 〜/ myfolder是否存在?运行该脚本的用户帐户是否有写入权限? –

回答

0

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

的东西,如

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