当前位置: 首页>>代码示例>>Python>>正文


Python FTP_TLS.retrlines方法代码示例

本文整理汇总了Python中ftplib.FTP_TLS.retrlines方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.retrlines方法的具体用法?Python FTP_TLS.retrlines怎么用?Python FTP_TLS.retrlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ftplib.FTP_TLS的用法示例。


在下文中一共展示了FTP_TLS.retrlines方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
 def sync(self):
     """
     downloads all needed_files from self.hostname (FTP)
     of the downloaded files, extracts .gz files to same local_working_dir
         -using self.extract function
     parses the .txt downloaded needed_files
         -using the self.parse function
     """
     ftps = FTP_TLS(self.hostname) # connect to host, default port
     ftps.login(self.username, self.password)
     ftps.prot_p()
     ftps.cwd(self.remote_dir) # change into "logs" directory
     ftps.retrlines('LIST *.gz *.txt', self.ftp_list_callback) # list directory contents
     for needed_file in self.needed_files:
         if self.logging:
             print "Writing {0} to {1}...".format(needed_file, self.local_working_dir)
         ftps.retrbinary("RETR " + needed_file, open(os.path.join(self.local_working_dir, needed_file), 'wb').write)
     if self.logging:
         print "done syncing files"
     for needed_file in self.needed_files:
         if needed_file.endswith(".gz"):
             self.extract(os.path.join(self.local_working_dir, needed_file))
         txt_file_name = needed_file.replace('.gz','')#if already a .txt file, this is unnceccessary but works.
         self.parse(txt_file_name)
     if self.logging:
         print "done extracting/parsing .gz files"
     ftps.quit()
开发者ID:tropo,项目名称:ftp_cdr_tool,代码行数:29,代码来源:ftp_cdr_tool.py

示例2: start

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
	def start(self):
		# create connection
		for ftpserver, users in self.db.iteritems():
			for s_user in users:
				self.log.log("Connecting to %s: user: %s pass: %s" % (ftpserver, s_user.user, s_user.passwd))
				ftp = FTP_TLS(ftpserver)     # connect to host, default port
				ftp.login(user=s_user.user, passwd=s_user.passwd) 
				ftp.prot_p()          # switch to secure data connection
				ftp.retrlines('LIST', self.parseFiles)
				self.log.log("Done! now quit...")
				ftp.quit()
开发者ID:yotam-gafni,项目名称:supertrends,代码行数:13,代码来源:FTPCrawler.py

示例3: ftp_backup

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
def ftp_backup(dmpdir,dbname):

    try:
#        
        ftp =FTP_TLS()
        ftp.connect(ftphost,ftpport)
        ftp.login(ftpuser,ftppass)
        ftp.prot_p()   
        print "Welcome:",ftp.getwelcome()
        print ftp.retrlines('LIST')
#         ftp =FTP()
#         ftp.connect(ftphost,ftpport)
#         ftp.login(ftpuser,ftppass)
#         print "Welcome:",ftp.getwelcome()
#         print ftp.retrlines('LIST')
    except Exception,e:
        print  e
        return
开发者ID:mmlvkk,项目名称:pythontest,代码行数:20,代码来源:oracle_backup_windows.py

示例4: connect

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
def connect(velkost_ftp,port):
    ftp=FTP_TLS(server,meno2,ps,port)   
    ftp.prot_p()
    ftp.cwd(my_list[2]) 
    print "Posielam subor. Cakajte prosim."
    obsah=open(file_to_send, 'rb')
    obsah.close()
    ftp.storbinary('STOR %s' % file_to_send, open(file_to_send, 'rb'))
    obsah.close()
    print "Subor odoslany [OK]"
    print "Obsah adresara na serveri:"
    ftp.retrlines("LIST")
    size_ftp=ftp.nlst()
    pocet=len(size_ftp)
    velkost_ftp_subor=size_ftp[pocet-1] #berie posledne pridany subor zo zoznamu
    ftp.sendcmd("TYPE i")
    velkost_ftp=ftp.size(velkost_ftp_subor) 
    ftp.close()
    return velkost_ftp
开发者ID:peterjs,项目名称:pyPNC,代码行数:21,代码来源:pypnc.py

示例5: download

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
def download(downloaded, user, passwd, all_files=False, filename=None):
    # Connect to the MAPS ftp server over FTPS
    ftps = FTP_TLS('ftps.tsi.telecom-paristech.fr')
    print 'Connected to MAPS FTP over TLS.'
    try:
        ftps.login(user=user, passwd=passwd)
        ftps.cwd('maps')
    except error_perm:
        print "Incorrect username/password" ; quit

    ftps.retrlines('LIST *.zip', get_file_list)

    if filename is not None:
        if not in_downloads(files, filename): print 'File not found' ; return
        print 'Downloading', filename
        res = ftps.retrbinary('RETR '+filename, open('./downloads/'+filename, 'wb').write)
        ftps.close()
        return [(filename, 0)]
    
    if len(files) == len(downloaded):
        print "All MAPS files downloaded. Continuing."
        return
    
    if all_files:
        for f, s in files:
            if not in_downloads(downloaded, f):
                print "Downloading", f, "of size", s, "bytes"
                res = ftps.retrbinary('RETR '+f, open('./downloads/'+f, 'wb').write)
    elif filename is None:
        f, s = random.choice(files)
        while in_downloads(downloaded, f):
            f, s = random.choice(files)
        
        print "Downloading", f, "of size", s, "bytes"
        res = ftps.retrbinary('RETR '+f, open('./downloads/'+f, 'wb').write)

    ftps.close()

    if all_files: return files
    return [(f, s)]
开发者ID:jbarrow,项目名称:capstone,代码行数:42,代码来源:maps_download.py

示例6: FTP_TLS

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
from ftplib import FTP_TLS
ftps = FTP_TLS('127.0.0.1:8021','user','12345',keyfile='privateKey.key')
ftps.login()           # login anonymously before securing control channel
ftps.prot_p()          # switch to secure data connection
print ftps.retrlines('LIST')
开发者ID:grillermo,项目名称:Jefe-Remoto,代码行数:7,代码来源:ftp+secure+client.py

示例7: FTP_TLS

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
from ftplib import FTP_TLS
ftps = FTP_TLS('202.157.143.104:12126')
ftps.login()
ftps.prot_p()
ftps.retrlines('LIST')
开发者ID:gongchengra,项目名称:hacker,代码行数:7,代码来源:ftpmy.py

示例8: FTP_TLS

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
from ftplib import FTP_TLS
ftps = FTP_TLS()
ftps.connect('127.0.0.1', 5000)
ftps.login('user', '12345')           # login anonymously before securing control channel
ftps.prot_p()          # switch to secure data connection
ftps.retrlines('LIST') # list directory content securely
开发者ID:weijia,项目名称:approot,代码行数:8,代码来源:sftpclient.py

示例9: FTPSession

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]
class FTPSession(object):
    """ Attempt to create some robustness and performance to FTPing """

    def __init__(self, server, username, password, tmpdir="/tmp", timeout=60):
        """Build a FTP session """
        self.conn = None
        self.server = server
        self.username = username
        self.password = password
        self.tmpdir = tmpdir
        self.timeout = timeout

    def _connect(self):
        """Connect to FTP server """
        if self.conn is not None:
            return
        logging.debug("Creating new connection to server %s", self.server)
        not_connected = True
        attempt = 1
        while not_connected and attempt < 6:
            try:
                self.conn = FTP_TLS(self.server, timeout=self.timeout)
                self.conn.login(self.username, self.password)
                self.conn.prot_p()
                not_connected = False
            except Exception as exp:
                logging.debug(exp)
                time.sleep(5)
                self.close()
            attempt += 1
        if not_connected is True:
            raise Exception("Failed to make FTP connection after 5 tries!")

    def _reconnect(self):
        """ First attempt to shut down connection and then reconnect """
        logging.debug("_reconnect() was called...")
        try:
            self.conn.quit()
            self.conn.close()
        except:
            pass
        finally:
            self.conn = None
        self._connect()

    def _put(self, path, localfn, remotefn):
        """ """
        self.chdir(path)
        sz = os.path.getsize(localfn)
        if sz > 14000000000:
            # Step 1 Split this big file into 14GB chunks, each file will have
            # suffix .aa then .ab then .ac etc
            basefn = os.path.basename(localfn)
            cmd = "split --bytes=14000M %s %s/%s." % (localfn, self.tmpdir, basefn)
            subprocess.call(cmd, shell=True, stderr=subprocess.PIPE)
            files = glob.glob("%s/%s.??" % (self.tmpdir, basefn))
            for filename in files:
                suffix = filename.split(".")[-1]
                self.conn.storbinary("STOR %s.%s" % (remotefn, suffix), open(filename))
                os.unlink(filename)
        else:
            logging.debug("_put '%s' to '%s'", localfn, remotefn)
            self.conn.storbinary("STOR %s" % (remotefn,), open(localfn))
        return True

    def close(self):
        """ Good bye """
        try:
            self.conn.quit()
            self.conn.close()
        except:
            pass
        finally:
            self.conn = None

    def chdir(self, path):
        if self.pwd() == path.rstrip("/"):
            return
        self.conn.cwd("/")
        for dirname in path.split("/"):
            if dirname == "":
                continue
            bah = []
            self.conn.retrlines("NLST", bah.append)
            if dirname not in bah:
                logging.debug("Creating directory '%s'", dirname)
                self.conn.mkd(dirname)
            logging.debug("Changing to directory '%s'", dirname)
            self.conn.cwd(dirname)

    def pwd(self):
        """ Low friction function to get connectivity """
        self._connect()
        pwd = exponential_backoff(self.conn.pwd)
        if pwd is None:
            self._reconnect()
            pwd = exponential_backoff(self.conn.pwd)
        logging.debug("pwd() is currently '%s'", pwd)
        return pwd

#.........这里部分代码省略.........
开发者ID:akrherz,项目名称:pyIEM,代码行数:103,代码来源:ftpsession.py

示例10: ServerWatcher

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrlines [as 别名]

#.........这里部分代码省略.........
                # Permissions test passed, now let's test MFMT for timestamp modification.
                if not self.testMFMT():
                    ok = False
                    msg = 'This server does not support timestamp modification\n \
                           need by this application.'

        self.loginCompleted.emit(ok, msg)
        
    def getFiles(self, path):
        """
        This method simply wraps the `nlst` method with an exception handler,
        and returns an empty list in case an exception is caught.
        
        :param path: Relative or absolute path on the server
        """
        
        try:
            nlst = self.ftp.nlst(path)
            dirs = self.getDirs(path)
            
            # Files are items in nlst that are not in dirs
            files = [item for item in nlst if os.path.basename(item) not in dirs]
            
            return files
        except:
            print 'Exception in ServerWatcher.getDirs'
            info = traceback.format_exception(*sys.exc_info())
            for i in info: sys.stderr.write(i)
            return []
             
    def getDirs(self, path):
        """
        Retrieves a list of the directories inside `path`,
        uses `retrlines` and the LIST command to retrieve the items.
        
        :param path: Relative or absolute path on the server
        """
        
        dirs = list()
        def handleLine(line):
            """
            Recieves a line from the LIST command.
            This function is meant to be used as callback for the `retrlines` method.
            
            :params line: Line from the LIST command
            """

            if line.startswith('d'):
                # Only lines starting with 'd' are directories
                # Parse the directory out of the line; lines look like:
                # 'drwxrwxrwx   1 user     group           0 Jun 15  2012 dirname'
                dirname = line[55:].strip()
                if dirname != '.' and dirname != '..':
                    # Ignoring '.' and '..' entries
                    dirs.append(dirname)
        
        try:
            self.ftp.retrlines('LIST %s' % path, handleLine)
            
            return dirs
        except:
            print 'Exception in ServerWatcher.getDirs'
            info = traceback.format_exception(*sys.exc_info())
            for i in info: sys.stderr.write(i)
            return []
    
开发者ID:ShareByLink,项目名称:iqbox-ftp,代码行数:69,代码来源:watchers.py


注:本文中的ftplib.FTP_TLS.retrlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。