Chapter 7: Interacting with FTP, SSH, and SNMP Servers

 

  1. How do we connect to an FTP server using the ftplib module through the connect() and login() methods?

ftp = FTP()
ftp.connect(host, 21)
ftp.login(‘user’, ‘password’)

 

  1. What method of the ftplib module allows it to list the files of an FTP server?

FTP.dir()

 

  1. Which method of the Paramiko module allows us to connect to an SSH server and with what parameters (host, username, password)?

ssh = paramiko.SSHClient()
ssh.connect(host, username=’username’, password=’password’)

 

  1. Which method of the Paramiko module allows us to open a session to be able to execute commands subsequently?

ssh_session = client.get_transport().open_session()

 

  1. How do we log in to an SSH server with an RSA certificate from which we've found out the route and password?

rsa_key= RSAKey.from_private_key_file('path_key_rsa',password)
client.connect('host',username='',pkey= rsa_key,password='')

 

  1. Which main class of the PySNMP module allows queries on SNMP agents?

CommandGenerator. Here's an example of its use:

from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()

 

  1. What is the instruction for informing Paramiko to accept server keys for the first time without interrupting the session or prompting the user?

ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

 

  1. Which way of connecting to an SSH server through the Transport() method provides another type of object to authenticate against the server?

transport = paramiko.Transport(ip_address)
transport.start_client()

 

  1. What is the Python FTP module, based in Paramiko, that provides a connection with FTP servers in a secure way?

pysftp, which is based on paramiko.

 

  1. Which  method from ftplib do we need to use to download files, and which ftp command do we need to execute?

file_handler = open(DOWNLOAD_FILE_NAME, 'wb')
ftp_cmd = 'RETR %s' %DOWNLOAD_FILE_NAME
ftp_client.retrbinary(ftp_cmd,file_handler.write)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178