from socket import *
from ssh2.session import Session
from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR
sock = socket(AF_INET,SOCK_STREAM,0)
sock.connect(("121.37.18.151",22))
session = Session()
session.handshake(sock)
print(session.userauth_list('myname'))
session.userauth_password('myname','mypassword')
channel = session.open_session()
channel.execute('ls -l')
size,data = channel.read()
while size > 0:
print(data)
size,data = channel.read()
sftp = session.sftp_init()
with sftp.open("1.txt",LIBSSH2_FXF_READ,LIBSSH2_SFTP_S_IRUSR) as remote_fh, open("1.txt",'wb') as local_fh:
for size,data in remote_fh:
local_fh.write(data)