Reference resources :Python— Realization sftp client ( Connect to remote server )
import paramiko
transport = paramiko.Transport(("106.15.88.182", 10022)) # obtain Transport example
transport.connect(username="root", password="123456") # Establishing a connection
# establish sftp object ,SFTPClient It defines how to transfer files 、 How to exchange files
sftp = paramiko.SFTPClient.from_transport(transport)
# Will local api.py Upload to server /www/test.py. File upload and rename to test.py
sftp.put("E:/test/api.py", "/www/test.py")
# Put the server /www/test.py Download to local aaa.py. Download the file and rename it to aaa.py
sftp.get("/www/test.py", "E:/test/aaa.py")
# Close the connection
transport.close()
The content is as follows, successfully called :
<SFTPAttributes: [ size=898 uid=1024 gid=1000 mode=0o100644 atime=1596798226 mtime=1596798226 ]>