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它失敗。我錯了什麼?
你是如何運行腳本替換
? 〜/ myfolder是否存在?運行該腳本的用戶帳戶是否有寫入權限? –