Need to use paramiko library

 

Upload local files to the server . Add the ip,port,username,password Complete supplement , Use it uploadfiletoserver Function to upload local files to the server
import paramiko ip = ""# The server ip port = 22# Port number username = "root"# user name password =
""# password def
uploadfiletoserver(local,remote):# Upload file to server .local Is the local path to upload the file ;remote Is the path to upload to the server
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip, port,
username, password) sftp = ssh.open_sftp() sftp.put(local, remote) return remote
 

Remote open server file :
import paramiko ip = ""# The server ip port = 22# Port number username = "root"# user name password =
""# password def openremotefile(filepath):#filepath Is the absolute path to the file to be opened on the server client =
paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(ip,
port, username, password, compress=True) sftp_client = client.open_sftp()
remotefile = sftp_client.open(filepath) # File path return remotefile
 

All codes
import paramiko ip = ""# The server ip port = 22# Port number username = "root"# user name password =
""# password def
uploadfiletoserver(local,remote):# Upload file to server .local Is the local path to upload the file ;remote Is the path to upload to the server
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip, port,
username, password) sftp = ssh.open_sftp() sftp.put(local, remote) return
remote def openremotefile(filepath):#filepath Is the absolute path to the file to be opened on the server client =
paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(ip,
port, username, password, compress=True) sftp_client = client.open_sftp()
remotefile = sftp_client.open(filepath) # File path return remotefile
 

Technology