Scp using paramiko does not work - ssh works fine

I was able to use the ssh and issue command on the remote server. Now I want scp files from a remote server, but that just seems impossible. I am completely new to python and Paramiko. The error is resolved in my local worm window directory. Files are supposed to come from a Mac. Any other really simple example that I can use to scp files from a remote Linux computer to a 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)
+5
source share
2 answers

To get files from a remote host to a local directory:

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

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

scp, , paramiko scp , , .

, , , , SO. , .

+8

All Articles