我們要了解幾個函數:
paramiko.Tranport(("目標ip,端口"))#這是上傳目標的IP和端口
paramiko.SFTPClient.from_tranport()#安全文件傳輸憑證
sftp.put(loaclfile,remotefile)#loaclfile是要上傳的文件,remotefile是上傳后要保存的文件名
代碼版:
import paramiko ssh=paramiko.Transport(("192.168.223.129",22)) ssh.connect(username="root",password="root") sftp=paramiko.SFTPClient.from_transport(ssh) localfile="使用說明.txt" remotefile="使用說明.txt" try: sftp.put(localfile,remotefile) except Exception: print("[-]put Error:User name or password error or uploaded file does not exist") print("上傳") ssh.close()
成功圖:
轉載請注釋:來自本地址