D3l_Gato
D3l_Gato

Reputation: 1329

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'

Upvotes: 4

Views: 5819

Answers (2)

John Percival Hackworth
John Percival Hackworth

Reputation: 11531

You may also have a problem if there isn't a directory named balls off your root directory on the remote host.

Upvotes: 1

sarnold
sarnold

Reputation: 104100

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.

Upvotes: 5

Related Questions