简体   繁体   中英

sftp from windows to unix with Python

I am trying to sftp a file from my Windows laptop to a Unix box (Juniper router).

I wrote a small script but it says I have the remote path wrong. i know there is probably something fancy I need to add so windows can translate the nix directory but I can't find it on Google :(

Here is the script:

import paramiko
host = "192.168.1.87"
port = 22
transport = paramiko.Transport((host, port)) 
password = "juniper123"
username = "root"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
filepath = '/balls/test.txt'
localpath = 'C:\Users\python1\test.txt'
sftp.put(filepath, localpath)
sftp.close()
transport.close()

I get the error:

WindowsError: [Error 3] The system cannot find the path specified: '/balls/test.txt'

sftp.put(filepath, localpath)

I believe you've swapped the local and remote paths. Try:

sftp.put(localpath, filepath)

For some details, see the API .

如果远程主机上的根目录中没有名为balls的目录,则可能会出现问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM