Example #1
0
 def connect(self):
     """
     Tente de se connecter
     """
     try:
         self.ftp = Ftp(self.address, self.user, self.port, self.timeout)
         self.ftp.connect(self.address, self.port)
         self.ftp.login(self.user, self.password)
         if Config.is_prot_d() is True:
             self.ftp.prot_p()
         self.test_prot_d()
         return ("connected", self.ftp)
     except ftplib.all_errors as e:
         e = str(e)
         print("\n")
         error(e + "\n")
         if 'TLS' in e or 'plain' in e:
             cprint(
                 "[b]Solution[/b]: Change the \"[b][blue]ftps[/blue][/b]\" options to "
                 "\"[b][green]true[/green][/b]\" in \"[warning]{}[/warning]\"\n"
                 .format(Config.get_config_path_for_print_only()))
         elif 'incorrect' in e or 'password' in e:
             cprint(
                 "[b]Solution[/b]: Be sure to have the right \"[b][blue]address[/blue][/b]\","
                 " \"[b][blue]address[/blue][/b]\","
                 " \"[b][blue]user[/blue][/b]\" and"
                 " \"[b][blue]port[/blue][/b]\""
                 " in \"[warning]{}[/warning]\"\n".format(
                     Config.get_config_path_for_print_only()))
         sys.exit(1)
Example #2
0
 def test_prot_d(self):
     try:
         sys.stdout = open(os.devnull, 'w')
         self.ftp.retrlines('LIST')
         sys.stdout = sys.__stdout__
     except:
         print("\n")
         error("PROT P required\n")
         cprint(
             "[b]Solution[/b]: Change the \"[b][blue]prot_d[/blue][/b]\" options to \"[b][green]true[/green][/b]\" in \"[warning]{}[/warning]\"\n"
             .format(Config.get_config_path_for_print_only()))
         sys.exit(1)