IOError: [Errno 2] No such file - Paramiko put() image on a vm

问题描述 投票:0回答:0

我正在使用 paramiko 3.1 将图像发送到我的虚拟机 ubuntu 22.04,但是我在这样做时遇到了错误。路径文件很好,虚拟机上的文件夹也存在这里是我的代码:

def sendSFTPFile(connexion, serverPath, localPath):
    sftp=connexion.open_sftp()
    Files = os.listdir(localPath)
    for file in Files:

        localfile=os.path.join(localPath,file)
        localfile=os.path.normpath(localfile)
        remotefile=os.path.normpath(os.path.join(serverPath,file))
        remotefile=remotefile.replace('\\', '/')
        print(f"localfile : {localfile} , remotefile : {remotefile}")
        sftp.put(localfile, remotefile)`

错误轨迹是:

Traceback (most recent call last):
  File "C:\ProgBundle\python3\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\ProgBundle\python3\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "N:\bureau\Fac\stage\LaMuse\RomeoLamuse.py", line 84, in <module>
    connectToRomeo(hostname=default_hostname,
  File "N:\bureau\Fac\stage\LaMuse\RomeoLamuse.py", line 25, in connectToRomeo
    sendSFTPFile(connexion,  "~/LaMuse/Backgrounds",background_folder)
  File "N:\bureau\Fac\stage\LaMuse\tools\supercalculator_connect.py", line 34, in sendSFTPFile
    sftp.put(localfile, remotefile)
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 759, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 714, in putfo
    with self.file(remotepath, "wb") as fr:
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 372, in open
    t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 822, in _request
    return self._read_response(num)
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 874, in _read_response
    self._convert_status(msg)
  File "C:\ProgBundle\python3\lib\site-packages\paramiko\sftp_client.py", line 903, in _convert_status
    raise IOError(errno.ENOENT, text)
FileNotFoundError: [Errno 2] No such file

我已经尝试像其他问题所说的那样在我的文件夹上授予所有权利 这就是我能做的更多

python ssh sftp paramiko
© www.soinside.com 2019 - 2024. All rights reserved.