尝试使用以下代码从Linux上的远程服务器获取文件:
import paramiko
from paramiko import SSHClient, AutoAddPolicy
from scp import SCPClient
class SSH_Connection:
def __init__(self, LOCAL_IP, username, password):
self.LOCAL_IP = LOCAL_IP
self.username = username
self.password = password
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(self.LOCAL_IP, username=self.username,password=self.password)
self.scp = SCPClient(self.client.get_transport())
def std(self, message):
self.message = message
_in, out, err = self.client.exec_command(self.message)
exitcode = out.channel.recv_exit_status()
stdout = ''.join(out.read())
stderr = ''.join(err.read())
return stdout, stderr, exitcode
class _scp(SSH_Connection):
def scp_put_file( self, localpath, remotepath):
self.scp.put(localpath, remotepath)
return
def scp_get_file( self, localpath):
self.scp.get(localpath)
unit = _scp('1.1.1.1', 'username', 'password')
可以,但是我无法将文件放入特定文件夹中。但是,SSH连接已建立,获取文件后将其发送到运行代码的文件夹中,但我希望特定的文件夹将文件复制到