[Python] Python Paramiko Filename needed on put command but

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    Environment: Windows DataCenter 2019.

    I'm trying to send a file using Python/Paramiko to a non-standard sftp host. I believe it's a mainframe but I'm not sure. Destination filename needs to be, "//ABC.AB4.C3943.S46200_942145". That is the actual filename and it goes into the "root" folder because the remote host does the translation into whatever file system it needs. Behind the scenes, I suspect the dots are folders, but doesn't really matter.

    What I'm getting from Paramiko appears to be the, "you must enter a destination filename" on the put statement error. I putting a filename. Just not what Paramiko expects?

    Any ideas around this? Error log below... Code snippet below that...

    Uploading \\xyz\tech\automation\temp\S46200_942145 to //ABC.AB4.C3943.S46200_942145
    Traceback (most recent call last):
    File "\\xyz\tech\Automation\scripts\dev\custom_jobs\Send_Files\generic_send_files.py", line 54, in <module>
    r = sftp.put(source, destination)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 759, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 714, in putfo
    with self.file(remotepath, "wb") as fr:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 372, in open
    t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 857, in _request
    return self._read_response(num)
    ^^^^^^^^^^^^^^^^^^^^^^^^
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 909, in _read_response
    self._convert_status(msg)
    File "c:\Automation\venv\Lib\site-packages\paramiko\sftp_client.py", line 942, in _convert_status
    raise IOError(text)
    OSError: Failure


    for files in os.listdir(source_path):
    if fnmatch.fnmatch(files, source_pattern):
    source = source_path + files
    destination = remote_folder + files
    print(f'Uploading {source} to {destination}')
    r = sftp.put(source, destination)
    print('Result:', r)


    I don't know what to try.

    I need the provided filename to be used/accepted by the put command.

    Continue reading...

Compartilhe esta Página