Reputation: 285
I'm trying to save a file from a remote server to my local pc. I've tried the following code:
import scp
client = scp.SCPClient("ip", "username", "password")
# and then
client.transfer('remote/file', 'C:\folder')
but doing so I'm getting the following error:
File "C:\Users\localfp\AppData\Local\Programs\Python\Python310\lib\site-packages\scp.py", line 156, in __init__
self.peername = self.transport.getpeername()
AttributeError: 'str' object has no attribute 'getpeername'
can you explain me what is this kind of error and how to fix it?
Upvotes: 1
Views: 610
Reputation: 285
I've found this solution:
import paramiko
from scp import SCPClient
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("IP address",username="xxxx", password="xxx")
scp = SCPClient(ssh.get_transport())
scp.get('remote path', 'local path')
Upvotes: 1
Reputation: 880
SCPClient
does not take arguments like ip, username or password. It accepts transport. Check the constructor.
def __init__(self, transport, buff_size=16384, socket_timeout=10.0, progress=None, progress4=None, sanitize=_sh_quote):
Connect using paramiko and pass the object to SCPClient.
from paramiko import SSHClient
from scp import SCPClient
with SSHClient() as ssh:
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("ip", username="username", password="password")
with SCPClient(ssh.get_transport()) as client:
client.transfer('remote/file', 'C:\folder')
Upvotes: 1