Python ftplib.all_errors() Examples

The following are 30 code examples of ftplib.all_errors(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ftplib , or try the search function .
Example #1
Source File: urllib.py    From meddle with MIT License 7 votes vote down vote up
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] 
Example #2
Source File: ftpbrute.py    From Vaile with GNU General Public License v3.0 6 votes vote down vote up
def ftpBrute0x00(ip, usernames, passwords, port, delay):

    ftp = FTP()
    for username in usernames:
        for password in passwords:
            try:
                ftp.connect(ip, port)
                ftp.login(username, password)
                print(G + ' [+] Username: %s | Password found: %s\n' % (username, password))
                ftp.quit()
                exit(0)
            except ftplib.error_perm:
                print(GR+ " [*] Checking : "+C+"Username: %s | "+B+"Password: %s "+R+"| Incorrect!\n" % (username, password))
                sleep(delay)
            except ftplib.all_errors as e:
                print(R+" [-] Error caught! Name: "+str(e))
            except KeyboardInterrupt:
                ftp.quit() 
Example #3
Source File: urllib.py    From Computable with MIT License 6 votes vote down vote up
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] 
Example #4
Source File: urllib.py    From oss-ftp with MIT License 6 votes vote down vote up
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, retrlen = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2] 
Example #5
Source File: urllib.py    From BinderFilter with MIT License 6 votes vote down vote up
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, retrlen = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2] 
Example #6
Source File: ftpanon.py    From d4rkc0de with GNU General Public License v2.0 6 votes vote down vote up
def scan():

	iprange = args[0]
	ip_list = []
	
	nmap = StringIO.StringIO(commands.getstatusoutput('nmap -P0 '+iprange+' -p 21 | grep open -B 3')[1]).readlines()
	
	for tmp in nmap:
		ipaddr = re.findall("\d*\.\d*\.\d*\.\d*", tmp)
		if ipaddr:
	    		ip_list.append(ipaddr[0])
	print "Found",len(ip_list),"hosts with ftp port open.\n"
		   

	for ip in ip_list:
		try:
			print "Checking for anonymous login on",ip
			ftp = FTP(ip)
			ftp.login()
			ftp.retrlines('LIST')
			print "\n\tAnonymous login successful on",ip,"\n"
			ftp.quit()
		except (ftplib.all_errors), msg: print "An error occurred:", msg
		
#................................................ 
Example #7
Source File: urllib.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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, retrlen = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2] 
Example #8
Source File: ftp.py    From django-storages with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _mkremdirs(self, path):
        pwd = self._connection.pwd()
        path_splitted = path.split(os.path.sep)
        for path_part in path_splitted:
            try:
                self._connection.cwd(path_part)
            except ftplib.all_errors:
                try:
                    self._connection.mkd(path_part)
                    self._connection.cwd(path_part)
                except ftplib.all_errors:
                    raise FTPStorageException(
                        'Cannot create directory chain %s' % path
                    )
        self._connection.cwd(pwd)
        return 
Example #9
Source File: ftprand.py    From d4rkc0de with GNU General Public License v2.0 6 votes vote down vote up
def ftpcheck(ipaddr):
	
	try:
		print "\n[+] Checking anonymous login:",ipaddr
		ftp = ftplib.FTP(ipaddr)
		print "[+] Response:",ftp.getwelcome()
		ftp.login()
		ftp.retrlines('LIST')
		print "\t[!] Anonymous login successful:",ipaddr
		print "[+] Testing Upload"
		ftp.sendcmd('PUT '+file)
		print "[+] Currect Directory:",ftplib.pwd()
		print "\t[!] Upload successful:",ipaddr
		ftp.quit()
	except (ftplib.all_errors), msg: 
		print "[-] An error occurred:",msg,"\n"
	
#................................................ 
Example #10
Source File: ftpbrute_random.py    From d4rkc0de with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #11
Source File: urllib.py    From pmatic with GNU General Public License v2.0 6 votes vote down vote up
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, retrlen = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2] 
Example #12
Source File: urllib.py    From datafari with Apache License 2.0 6 votes vote down vote up
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, retrlen = self.ftp.ntransfercmd(cmd)
            except ftplib.error_perm, reason:
                if str(reason)[:3] != '550':
                    raise IOError, ('ftp error', reason), sys.exc_info()[2] 
Example #13
Source File: ftp.py    From django-storages with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _get_dir_details(self, path):
        # Connection must be open!
        try:
            lines = []
            self._connection.retrlines('LIST ' + path, lines.append)
            dirs = {}
            files = {}
            for line in lines:
                words = line.split()
                if len(words) < 6:
                    continue
                if words[-2] == '->':
                    continue
                if words[0][0] == 'd':
                    dirs[words[-1]] = 0
                elif words[0][0] == '-':
                    files[words[-1]] = int(words[-5])
            return dirs, files
        except ftplib.all_errors:
            raise FTPStorageException('Error getting listing for %s' % path) 
Example #14
Source File: ftp.py    From django-storages with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def exists(self, name):
        self._start_connection()
        try:
            nlst = self._connection.nlst(
                os.path.dirname(name) + '/'
            )
            if name in nlst or os.path.basename(name) in nlst:
                return True
            else:
                return False
        except ftplib.error_temp:
            return False
        except ftplib.error_perm:
            # error_perm: 550 Can't find file
            return False
        except ftplib.all_errors:
            raise FTPStorageException('Error when testing existence of %s'
                                      % name) 
Example #15
Source File: ftpbrute_random.py    From d4rkc0de with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #16
Source File: urllib2.py    From jawfish with MIT License 5 votes vote down vote up
def ftp_open(self, req):
        host = req.get_host()
        if not host:
            raise IOError('ftp error', 'no host given')
        # XXX handle custom username & password
        try:
            host = socket.gethostbyname(host)
        except socket.error(msg):
            raise URLError(msg)
        host, port = splitport(host)
        if port is None:
            port = ftplib.FTP_PORT
        path, attrs = splitattr(req.get_selector())
        path = unquote(path)
        dirs = path.split('/')
        dirs, file = dirs[:-1], dirs[-1]
        if dirs and not dirs[0]:
            dirs = dirs[1:]
        user = passwd = '' # XXX
        try:
            fw = self.connect_ftp(user, passwd, host, port, dirs)
            type = file and 'I' or 'D'
            for attr in attrs:
                attr, value = splitattr(attr)
                if attr.lower() == 'type' and \
                   value in ('a', 'A', 'i', 'I', 'd', 'D'):
                    type = value.upper()
            fp, retrlen = fw.retrfile(file, type)
            headers = ""
            mtype = mimetypes.guess_type(req.get_full_url())[0]
            if mtype:
                headers += "Content-Type: %s\n" % mtype
            if retrlen is not None and retrlen >= 0:
                headers += "Content-Length: %d\n" % retrlen
            sf = StringIO(headers)
            headers = mimetools.Message(sf)
            return addinfourl(fp, headers, req.get_full_url())
        except ftplib.all_errors(msg):
            raise IOError(('ftp error', msg), sys.exc_info()[2]) 
Example #17
Source File: request.py    From telegram-robot-rss with Mozilla Public License 2.0 5 votes vote down vote up
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 
Example #18
Source File: ftpbrute_iprange.py    From d4rkc0de with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #19
Source File: request.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 
Example #20
Source File: ftpbrute.py    From d4rkc0de with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #21
Source File: brute_ftp.py    From teye_scanner_for_book with GNU General Public License v3.0 5 votes vote down vote up
def Login(ServerIP, username, password):
    '''
    '''
    f = ftplib.FTP()
    f.connect(ServerIP, 21, timeout=10)
    print "Login FTP..."
    try:
        f.login(username, password)
    except ftplib.all_errors:
        print "Error:Server %s Cannot Login by the Account(%s,%s)" % (ServerIP, username, password)
        f.quit()
        return False

    return True 
Example #22
Source File: request.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #23
Source File: request.py    From blackmamba with MIT License 5 votes vote down vote up
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 
Example #24
Source File: ftpbrute_random1.0.py    From d4rkc0de with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
		value = getword()
		try:
			print "-"*12
			print "User:",user[:-1],"Password:",value
			ftp = FTP(ipaddr[0])
			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 
Example #25
Source File: cli.py    From ftpknocker with MIT License 5 votes vote down vote up
def scan(hosts, port, timeout):
    for host in hosts:
        try:
            ftp = ftplib.FTP()
            ftp.connect(host, port, timeout)
            if '230' in ftp.login(user=ANONYMOUS_USER, passwd=ANONYMOUS_PASSWORD):
                print(host)
                ftp.quit()
        except ftplib.all_errors:
            pass 
Example #26
Source File: urllib.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #27
Source File: request.py    From Imogen with MIT License 5 votes vote down vote up
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 
Example #28
Source File: test_ftplib.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #29
Source File: test_ftplib.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #30
Source File: request.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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