Doublespeed
Doublespeed

Reputation: 1173

scp using paramiko doesnt work - ssh works fine

I have been able to use ssh and issue command in the remote server. Now I want to scp files from the remote server but that just seems like its impossible. I'm totally new to python and Paramiko. The error is permission denied in my local directory of darn windows. The files are supposed to come from the Mac. Any other really really simple example I can use to scp files from a remote Linux machine to my local Windows machine?

import paramiko


hostname = '192.xx.1.xx'
password = 'pop123'
username = "husbad2"
port = 22

mypath='C:\\Users\\handsonexpert\\Documents'
remotepath='/Users/ihussain/testdir/file3.txt'


t = paramiko.Transport((hostname, 22))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(mypath, remotepath)

Upvotes: 7

Views: 31305

Answers (2)

Ali-Akber Saifee
Ali-Akber Saifee

Reputation: 4616

To retrieve files from a remote host into a local directory:

......
localpath='C:\\Users\\handsonexpert\\Documents\\file3.txt'
remotepath='/Users/ihussain/testdir/file3.txt'
......
sftp.get(remotepath, localpath)

Upvotes: 11

danodonovan
danodonovan

Reputation: 20373

You're not using scp here, but SFTP (SFTPClient).

If you're set on using scp, maybe take a look at this paramiko scp client, there is an example of how to use it here.

Aside, out of general security interests and programming style, don't hard code your password and user credentials, and especially never publish them in a public forum like SO. We don't need them and you don't need to post them.

Upvotes: 8

Related Questions