I am new to python and I am trying to find a efficient way to get user input for the following and pass them as arguments in function while using classes. I am new to oops and I am finding it hard to get user input from user while implementing classes and objects
Can someone help me how do I efficiently get user input for the following in the code below : remote upload_local_path download_local
class Myclass:
def __init__(self, hostname, user, password):
self.hostname = hostname
self.user = user
self.password = password
def connect_paramiko(self):
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.hostname, port=22, username=self.user, password=self.password)
print("connected successfully")
return ssh
def uploadtoRemote(self,myhost,myusername,mypassword,remote_path, upload_local_path):
ssh = self.connect_paramiko()
sftp = ssh.open_sftp()
files = os.listdir(upload_local_path)
for file in files:
sftp.put(os.path.join(upload_local_path, file), remote_path "/" file)
sftp.close()
def downloadtoLocal(self,remote,download_local):
'''getting the file from remote to local host'''
ssh = self.connect_paramiko()
sftp = ssh.open_sftp()
self.inbound_files = sftp.listdir(remote)
for ele in self.inbound_files:
sftp.get(remote, download_local)
sftp.close()
ssh.close()
if __name__ == "__main__":
m1=Myclass("abc.com","user", "user")
remote="abc.com"
upload_local_path="/abc/book/lib"
download_local="/abc/book/efg"
m1.uploadtoRemote("abc.com","user", "user",upload_local_path)
m1.downloadtoLocal(remote,download_local) '''
CodePudding user response:
Like this:
if __name__ == "__main__":
remote=input("Enter the remote system name: ")
user=input("Enter your username: ")
passwd=input("Enter the password (insecure): ")
upload_local_path=input("Enter the local upload path: ")
download_local=input("Enter the local download path: ")
m1=Myclass(remote, user, passwd)
m1.uploadtoRemote(remote, user, passwd,upload_local_path)
m1.downloadtoLocal(remote,download_local)