gpt4 book ai didi

python - Paramiko Python : IOError: [Errno 13] Permission denied

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:42 48 4
gpt4 key购买 nike

问题:

我可以这样做吗:

self.sftp.put(sourceFilePath, final_destination, use_sudo=True)

我可以创建文件夹,但不能创建文件?我是否需要显式调用 sudo 或在 paramiko 中设置某些内容?我应该将文件复制到允许的空间并更改吗?有没有办法在不使用 key 或不必乱用 ssh.exec_command("sudo mv") 的情况下提供 paramikko sudoer?我错过了什么?

代码:

class Ssh(object):

def __init__(self):
super(Ssh, self).__init__()

def setup(self):
'''Setup connection'''
try:
# DEBUG
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
#set username & password
username = 'sgdevbox'
password = MainFrame.ssh_pass
host = '192.168.0.170'
port = 22
self.transport = paramiko.Transport((host, port))
self.transport.connect(username = username, password = password)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
print(self.sftp.sock)
except Exception, e:
print(traceback.format_exc())

def putFiles(self, sources, listingSku):
'''
Upload images to server along with all currentItemInfo, plus initials and date
Basically build the auction and put it into the queue for verification
'''
print('\n# Ssh.putFiles() #')
if isinstance(sources, unicode):
sources = {sources,'True'}
try:
self.setup()
destination = '/var/www'
cwd = os.getcwd()
for source in sources:
filename = os.path.split(source)[-1]
destinationFolder = listingSku
final_path = posixpath.join(destination,destinationFolder)

try:
self.sftp.mkdir(final_path, mode=777)
except:
print(traceback.format_exc())
final_destination = posixpath.join(final_path, filename)
sourceFilePath = os.path.join(cwd,source)
print('\n# Source Path: {}\n# Destination Path: {}\n\n'.format(sourceFilePath,final_destination))
self.sftp.put(sourceFilePath, final_destination)
except Exception, e:
print(traceback.format_exc())
return

追溯:

# Source Path: C:\A\Long\Path\622-402_01.JPEG
# Destination Path: /var/www/WOOBLE-WAMBLER-SPAM-1235/622-402_01.JPEG


DEBUG:paramiko.transport.sftp:[chan 1] open('/var/www/WOOBLE-WAMBLER-SPAM-1235/622-402_01_swatch.JPEG', 'wb')
Traceback (most recent call last):
File "display_image.py", line 67, in putFiles
self.sftp.put(sourceFilePath, final_destination)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 565, in put
fr = self.file(remotepath, 'wb')
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 245, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 635, in _request
return self._read_response(num)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 682, in _read_response
self._convert_status(msg)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 710, in _convert_status
raise IOError(errno.EACCES, text)
IOError: [Errno 13] Permission denied

我看过的其他帖子:

有些帖子有点旧,但似乎表明 paramiko 没有实现它? Fabric 实现了一个版本,但我不确定是否要添加更多依赖项。

(Pdb) import pkg_resources
(Pdb) pkg_resources.get_distribution('paramiko').version
'1.13.0'

最佳答案

我对 sftp.get 有同样的错误

我尝试过:

sftp.get('/remote_server/readme.txt', localpath='C:\\Users\\user1\\Desktop')

得到上面的错误:[Errno 13] Permission denied

解决方法是我们需要指定包含文件名的整个路径。

sftp.get('/remote_server/readme.txt', localpath='C:\\Users\\user1\\Desktop\\readme.txt')

关于python - Paramiko Python : IOError: [Errno 13] Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23144286/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com