Python ftplib 模块,all_errors() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ftplib.all_errors()

项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def workhorse(ipaddr, user, word):
    user = user.replace("\n","")
    word = word.replace("\n","")
    try:
        print "-"*12
        print "User:",user,"Password:",word
        ftp = FTP(ipaddr)
        ftp.login(user, word)
        ftp.retrlines('LIST')
        print "\t\n[!] Login successful:",user, word
        if txt != None:
            save_file.writelines(user+" : "+word+" @ "+ipaddr+":21\n")
        ftp.quit()
        sys.exit(2)
    except (ftplib.all_errors), msg: 
        #print "[-] An error occurred:", msg
        pass
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def brute(ipaddr):
    print "-"*30
    print "\n[+] Attempting BruteForce:",ipaddr,"\n"
    try:
        f = FTP(ipaddr)
        print "[+] Response:",f.getwelcome()
    except (ftplib.all_errors):
        pass
    try:
        print "\n[+] Checking for anonymous login:",ipaddr,"\n"
        ftp = FTP(ipaddr)
        ftp.login()
        ftp.retrlines('LIST')
        print "\t\n[!] Anonymous login successful!!!\n"
        if txt != None:
            save_file.writelines("Anonymous:"+ipaddr+":21\n")
        ftp.quit()
    except (ftplib.all_errors): 
        print "[-] Anonymous login unsuccessful\n"
    for user in users:
        for word in words:
            work = threading.Thread(target = workhorse, args=(ipaddr, user, word)).start()
            time.sleep(1)
项目:robodk_postprocessors    作者:ros-industrial    | 项目源码 | 文件源码
def RemoveDirFTP(self, ftp, path):
        import ftplib
        """Recursively delete a directory tree on a remote server."""
        wd = ftp.pwd()
        try:
            names = ftp.nlst(path)
        except ftplib.all_errors as e:
            # some FTP servers complain when you try and list non-existent paths
            print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
            return

        for name in names:
            if os.path.split(name)[1] in ('.', '..'): continue
            print('RemoveDirFTP: Checking {0}'.format(name))
            try:
                ftp.cwd(name)  # if we can cwd to it, it's a folder
                ftp.cwd(wd)  # don't try a nuke a folder we're in
                self.RemoveDirFTP(ftp, name)
            except ftplib.all_errors:
                ftp.delete(name)

        try:
            ftp.rmd(path)
        except ftplib.all_errors as e:
            print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
项目:eemeter    作者:openeemeter    | 项目源码 | 文件源码
def _get_ftp_connection(self):
        for _ in range(self.n_tries):
            try:
                ftp = ftplib.FTP("ftp.ncdc.noaa.gov")
            except ftplib.all_errors as e:
                logger.warn("FTP connection issue: %s", e)
            else:
                logger.info(
                    "Successfully established connection to ftp.ncdc.noaa.gov."
                )
                try:
                    ftp.login()
                except ftplib.all_errors as e:
                    logger.warn("FTP login issue: %s", e)
                else:
                    logger.info(
                        "Successfully logged in to ftp.ncdc.noaa.gov."
                    )
                    return ftp
        raise RuntimeError("Couldn't establish an FTP connection.")
项目:orange3-imageanalytics    作者:biolab    | 项目源码 | 文件源码
def _load_image_from_url_or_local_path(self, file_path):
        urlparts = urlparse(file_path)
        if urlparts.scheme in ('http', 'https'):
            try:
                file = self._session.get(file_path, stream=True).raw
            except RequestException:
                log.warning("Image skipped", exc_info=True)
                return None
        elif urlparts.scheme in ("ftp", "data"):
            try:
                file = urlopen(file_path)
            except (URLError, ) + ftplib.all_errors:
                log.warning("Image skipped", exc_info=True)
                return None
        else:
            file = file_path

        try:
            return open_image(file)
        except (IOError, ValueError):
            log.warning("Image skipped", exc_info=True)
            return None
项目:pydwd    作者:ckaus    | 项目源码 | 文件源码
def get_modified_time_of_file(host, file_path, file_name):
    modified_time = 0
    try:
        ftp = ftplib.FTP(host)
        ftp.login()
        ftp.cwd(file_path)
        modified_time = ftp.sendcmd('MDTM %s' % file_name)[4:]
        ftp.quit()

        year = int(modified_time[:4])
        month = int(modified_time[4:6])
        day = int(modified_time[6:8])
        hour = int(modified_time[8:10])
        minute = int(modified_time[10:12])
        seconds = int(modified_time[12:14])

        remote_file_time = datetime.datetime(year, month, day, hour, minute, seconds)
        modified_time = int(time.mktime(remote_file_time.timetuple()))
    except ftplib.all_errors as e:
        logger.warning('%s\nNot able to get date of remote description file. Check your connection' % e)
    return modified_time
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def retrfile(self, file, type):
        import ftplib
        self.endtransfer()
        if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
        else: cmd = 'TYPE ' + type; isdir = 0
        try:
            self.ftp.voidcmd(cmd)
        except ftplib.all_errors:
            self.init()
            self.ftp.voidcmd(cmd)
        conn = None
        if file and not isdir:
            # Try to retrieve as a file
            try:
                cmd = 'RETR ' + file
                conn = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2]
        if not conn:
            # Set transfer mode to ASCII!
            self.ftp.voidcmd('TYPE A')
            # Try a directory listing. Verify that directory exists.
            if file:
                pwd = self.ftp.pwd()
                try:
                    try:
                        self.ftp.cwd(file)
                    except ftplib.error_perm, reason:
                        raise IOError, ('ftp error', reason), sys.exc_info()[2]
                finally:
                    self.ftp.cwd(pwd)
                cmd = 'LIST ' + file
            else:
                cmd = 'LIST'
            conn = self.ftp.ntransfercmd(cmd)
        self.busy = 1
        # Pass back both a suitably decorated object and a retrieval length
        return (addclosehook(conn[0].makefile('rb'),
                             self.endtransfer), conn[1])
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def run(self):
        value = getword()
        try:
            print "-"*12
            print "User:",user[:-1],"Password:",value
            ftp = FTP(ip)
            ftp.login(user[:-1], value)
            ftp.retrlines('LIST')
            print "\t\nLogin successful:",user, value
            ftp.quit()
            work.join()
            sys.exit(2)
        except (ftplib.all_errors), msg: 
            #print "An error occurred:", msg
            pass
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def ftpcheck(ftpdn):
    try:
    ftp=FTP(ftpdn)
        ftp.login()
        ftp.retrlines('list')
    print "\nAnonymous loging possible: Try running a make directory command"
    except(ftplib.all_errors),msg: print "Anonymous not Possible||Or Unknown Error"
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def run(self):
        value, user = getword()
        try:
            print "-"*12
            print "User:",user,"Password:",value
            ftp = FTP(sys.argv[1])
            ftp.login(user, value)
            ftp.retrlines('LIST')
            print "\t\nLogin successful:",value, user
            ftp.quit()
            work.join()
            sys.exit(2)
        except (ftplib.all_errors), msg: 
            #print "An error occurred:", msg
            pass
项目:routersploit    作者:reverse-shell    | 项目源码 | 文件源码
def ftp_get_config(self):
        print_status("FTP {}:{} Trying FTP authentication with Username: {} and Password: {}".format(self.target,
                                                                                                     self.ftp_port,
                                                                                                     self.remote_user,
                                                                                                     self.remote_pass))
        ftp = ftplib.FTP()

        try:
            ftp.connect(self.target, port=int(self.ftp_port), timeout=10)
            ftp.login(self.remote_user, self.remote_pass)

            print_success("FTP {}:{} Authentication successful".format(self.target, self.ftp_port))
            if self.config_path in ftp.nlst():
                print_status("FTP {}:{} Downloading: {}".format(self.target, self.ftp_port, self.config_path))
                r = StringIO()
                ftp.retrbinary('RETR {}'.format(self.config_path), r.write)
                ftp.close()
                data = r.getvalue()

                creds = re.findall(r'add name=(.*) password=(.*) role=(.*) hash2=(.*) crypt=(.*)\r\n', data)
                if creds:
                    print_success("Found encrypted credentials:")
                    print_table(('Name', 'Password', 'Role', 'Hash2', 'Crypt'), *creds)
                    return creds
                else:
                    print_error("Exploit failed - could not find any credentials")
        except ftplib.all_errors:
            print_error("Exploit failed - FTP error")

        return None
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def ftp_get_config(self):
        print_status("FTP {}:{} Trying FTP authentication with Username: {} and Password: {}".format(self.target,
                                                                                                     self.ftp_port,
                                                                                                     self.remote_user,
                                                                                                     self.remote_pass))
        ftp = ftplib.FTP()

        try:
            ftp.connect(self.target, port=int(self.ftp_port), timeout=10)
            ftp.login(self.remote_user, self.remote_pass)

            print_success("FTP {}:{} Authentication successful".format(self.target, self.ftp_port))
            if self.config_path in ftp.nlst():
                print_status("FTP {}:{} Downloading: {}".format(self.target, self.ftp_port, self.config_path))
                r = StringIO()
                ftp.retrbinary('RETR {}'.format(self.config_path), r.write)
                ftp.close()
                data = r.getvalue()

                creds = re.findall(r'add name=(.*) password=(.*) role=(.*) hash2=(.*) crypt=(.*)\r\n', data)
                if creds:
                    print_success("Found encrypted credentials:")
                    print_table(('Name', 'Password', 'Role', 'Hash2', 'Crypt'), *creds)
                    return creds
                else:
                    print_error("Exploit failed - could not find any credentials")
        except ftplib.all_errors:
            print_error("Exploit failed - FTP error")

        return None
项目:robodk_postprocessors    作者:ros-industrial    | 项目源码 | 文件源码
def RemoveFileFTP(ftp, filepath):
    """Delete a file on a remote server."""
    import ftplib    
    try:
        ftp.delete(filepath)
    except ftplib.all_errors as e:
        import sys
        print('POPUP: Could not remove file {0}: {1}'.format(filepath, e))
        sys.stdout.flush()
项目:robodk_postprocessors    作者:ros-industrial    | 项目源码 | 文件源码
def RemoveDirFTP(ftp, path):
    """Recursively delete a directory tree on a remote server."""
    import ftplib    
    wd = ftp.pwd()
    try:
        names = ftp.nlst(path)
    except ftplib.all_errors as e:
        # some FTP servers complain when you try and list non-existent paths
        print('RemoveDirFTP: Could not remove folder {0}: {1}'.format(path, e))
        return

    for name in names:
        if os.path.split(name)[1] in ('.', '..'): continue
        print('RemoveDirFTP: Checking {0}'.format(name))
        try:
            ftp.cwd(path+'/'+name)  # if we can cwd to it, it's a folder
            ftp.cwd(wd)  # don't try a nuke a folder we're in
            RemoveDirFTP(ftp, path+'/'+name)
        except ftplib.all_errors:
            ftp.delete(path+'/'+name)
            #RemoveFileFTP(ftp, name)

    try:
        ftp.rmd(path)
    except ftplib.all_errors as e:
        print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
项目:robodk_postprocessors    作者:ros-industrial    | 项目源码 | 文件源码
def RemoveFileFTP(self, ftp, filepath):
        import ftplib
        """Recursively delete a directory tree on a remote server."""
        try:
            ftp.delete(filepath)
        except ftplib.all_errors as e:
            import sys
            print('POPUP: Could not remove {0}: {1}'.format(filepath, e))
            sys.stdout.flush()
项目:robodk_postprocessors    作者:ros-industrial    | 项目源码 | 文件源码
def RemoveFileFTP(self, ftp, filepath):
        import ftplib
        """Recursively delete a directory tree on a remote server."""
        try:
            ftp.delete(filepath)
        except ftplib.all_errors as e:
            import sys
            print('POPUP: Could not remove {0}: {1}'.format(filepath, e))
            sys.stdout.flush()
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:A-Z-of-Python    作者:crvaden    | 项目源码 | 文件源码
def ftp_connect():  # Connect to the FTP and start asking for commands
    while True:  # If connection fails, retry
        site_address = input('Enter FTP address: ')
        try:

            with ftplib.FTP(site_address) as ftp:
                ftp.login()
                print(ftp.getwelcome())
                print('Directory Listing for', ftp.pwd())
                ftp.dir()
                print('Valid commands are cd/get/exit - ex: get readme.txt')
                ftp_command(ftp)
                break  # once ftp_command() exits, end this function (exit program)
        except ftplib.all_errors as e:  # treat all exceptions at this point as a connection failure
            print('Failed to connect, check your address.', e)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, OSError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, IOError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:VulScript    作者:y1ng1996    | 项目源码 | 文件源码
def brute_anony():
    try:
        print '[+] ??????……\n'
        ftp = ftplib.FTP()
        ftp.connect(host, 21, timeout=10)
        print 'FTP??: %s \n' % ftp.getwelcome()
        ftp.login()
        ftp.retrlines('LIST')
        ftp.quit()
        print '\n[+] ??????……\n'
    except ftplib.all_errors:
        print '\n[-] ??????……\n'
项目:VulScript    作者:y1ng1996    | 项目源码 | 文件源码
def brute_users(user, pwd):
    try:
        ftp = ftplib.FTP()
        ftp.connect(host, 21, timeout=10)
        ftp.login(user, pwd)
        ftp.retrlines('LIST')
        ftp.quit()
        print '\n[+] ?????????%s ???%s\n' % (user, pwd)
    except ftplib.all_errors:
        pass
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:pmatic    作者:LarsMichelsen    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def ftperrors():
    """Return the set of errors raised by the FTP class."""
    global _ftperrors
    if _ftperrors is None:
        import ftplib
        _ftperrors = ftplib.all_errors
    return _ftperrors
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_all_errors(self):
        exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
                      ftplib.error_proto, ftplib.Error, OSError, EOFError)
        for x in exceptions:
            try:
                raise x('exception not included in all_errors set')
            except ftplib.all_errors:
                pass