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


Python FTP_TLS.retrbinary方法代码示例

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


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

示例1: sync

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [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: get_file

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
	def get_file(filename):						# how do we 'stream' the file from Box to browser? using a callback!
		class VMFile:						# this will store the VM message as a 
  			def __init__(self):				# memory object instead of in a file (+ deleted after execution)
    				self.data = ""
  			def __call__(self,s):
     				self.data += s
		v = VMFile()
		session = FTP_TLS('ftp.box.com', box_username, box_password)	# open Box
		session.retrbinary('RETR recordings/' + filename, v)	# add each chunk of data to memory from Box
		session.close()						# close Box
		return v.data						# return the data put back together again to be sent to browser
开发者ID:ehhop,项目名称:ehhapp-twilio,代码行数:13,代码来源:voicemail_helpers.py

示例3: ftpDownload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def ftpDownload(filename):
    from ftplib import FTP_TLS
    import os
    
    ftps = FTP_TLS()
    ftps.connect('pwcrack.init6.me', '21')
    ftps.auth()
    ftps.login('DC214', 'passwordcrackingcontest')
    ftps.prot_p()
    ftps.set_pasv(True)
    local_filename = filename
    with open(local_filename, 'wb') as f:
        def callback(data):
            f.write(data)
        ftps.retrbinary('RETR %s' % filename, callback)
开发者ID:initiate6,项目名称:pwcrack,代码行数:17,代码来源:FTPdownload.py

示例4: ftp_files

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def ftp_files(domain, remote_paths, local_paths, direction, secure=True):
    ftp = FTP_TLS(domain) if secure else FTP(domain)
    ftp.login(prompt_usr(), prompt_pw())
    
    if secure:
        ftp.prot_p()
    
    for remote_path, local_path in zip(remote_paths, local_paths):
        if direction.lower() == 'up':
            ftp.storbinary('STOR ' + remote_path, open(local_path, 'rb'))
        elif direction.lower() == 'down':
            ftp.retrbinary('RETR ' + remote_path, open(local_path, 'wb').write)
        else:
            raise Exception('Invalid direction: ' + direction)
    
    ftp.quit()
开发者ID:prust,项目名称:sysadmin,代码行数:18,代码来源:__init__.py

示例5: getfiles

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def getfiles(server, port, user, password, db):
	sqliteconnection = sqlite3.connect(db)
	sqlitecursor = sqliteconnection.cursor()

	sqlitecursor.execute('''CREATE TABLE IF NOT EXISTS latest (date int, CONSTRAINT 'id_UNIQUE' UNIQUE ('date'))''')
	sqliteconnection.commit()

	sqlitecursor.execute('''SELECT date FROM files WHERE date = (SELECT MAX(date) FROM files) LIMIT 1''')
	latestfile = sqlitecursor.fetchone()

	sqlitecursor.execute('''SELECT date FROM latest WHERE date = (SELECT MAX(date) FROM latest) LIMIT 1''')
	latestfetch = sqlitecursor.fetchone()

	if latestfetch is None:
		latestfetch = 0

	if latestfetch < latestfile:
		ftpsconnection = FTP_TLS()
		ftpsconnection.connect(server, port)
		ftpsconnection.auth()
		ftpsconnection.prot_p()
		ftpsconnection.login(user, password)
		ftpsconnection.prot_p()

		sqlitecursor.execute('''SELECT name FROM files WHERE date > %d''' % latestfetch)
		filestofetch = sqlitecursor.fetchall()

		for currfile in filestofetch:
        		ftpsconnection.cwd(currfile[0])
			filenames = ftpsconnection.nlst()

			for filename in filenames:
				print 'Now saving /mnt/folder' + currfile[0] + '/' + filename
				localfile = open('/mnt/folder' + currfile + '/' + filename, 'wb')
				ftpsconnection.retrbinary('RETR ' + filename, localfile.write)
				localfile.close()


	sqliteconnection.execute('''INSERT OR IGNORE INTO latest VALUES (%d)''' % time.time())
	sqliteconnection.commit()

	sqliteconnection.close()
	ftpsconnection.quit()
	ftpsconnection.close()
开发者ID:sikevux,项目名称:FTPSync,代码行数:46,代码来源:Sync.py

示例6: get_ftp_data

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
 def get_ftp_data(self, cr, uid, ids, context={}):
     for chain in self.browse(cr, uid, ids, context=context):
         config_obj = chain.ftp_config_id
         try:
             conn = FTP_TLS(host=config_obj.host, user=config_obj.username, passwd=config_obj.passwd)
             conn.prot_p()
         except:
             conn = FTP(host=config_obj.host, user=config_obj.username, passwd=config_obj.passwd)
         filenames = conn.nlst()
         for filename in filenames:
             input_file = StringIO()
             conn.retrbinary('RETR %s' % filename, lambda data: input_file.write(data))
             input_string = input_file.getvalue()
             input_file.close()
             csv_reader = unicode_csv_reader(StringIO(input_string), delimiter=str(chain.separator), quoting=(not chain.delimiter and csv.QUOTE_NONE) or csv.QUOTE_MINIMAL, quotechar=chain.delimiter and str(chain.delimiter) or None, charset=chain.charset)
             self.import_to_db(cr, uid, ids, csv_reader=csv_reader, context=context)
             conn.delete(filename)
         conn.quit()
     return True
开发者ID:AbdelghaniDr,项目名称:ea_import,代码行数:21,代码来源:ea_import_chain.py

示例7: download

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [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

示例8: ftpDownload

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def ftpDownload(filename, system):
    from ftplib import FTP_TLS
    import os
    
    ftps = FTP_TLS()
    ftps.connect('pwcrack.init6.me', '21')
    ftps.auth()
    ftps.login('DC214', 'passwordcrackingcontest')
    ftps.prot_p()
    ftps.set_pasv(True)
    local_filename = filename
    with open(local_filename, 'wb') as f:
        def callback(data):
            print "Downloading %s ..." % filename
            f.write(data)
        ftps.retrbinary('RETR %s' % filename, callback)
    f.close()

    file_extension = str(filename.rsplit('.')[2])
    
    if file_extension == '7z':
        status = decompressit(local_filename, system)
        if status:
            print "file %s has been downloaded." % local_filename
开发者ID:initiate6,项目名称:pwcrack,代码行数:26,代码来源:setup.py

示例9: get_stock_data

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def get_stock_data():
    """ 
        Get item stock data from csv.
        Returns: { itemRef: [ {'options': [option_dict], 'price': [price_dict], 'inventory': int} ] }
        
        * option_dict = {'option_type': string, 'option_value': string, 'attributes': [attrib_dict]}
        ** attrib_dict = {'attribute_type': string, 'attribute_value': string}
        
        * price_dict = {'price_type': string, 'price': float, 'quantity_break_start': float, 'quantity_break_end': float}
        ** 'price_type', 'quantity_break_start' and 'quantity_break_end' are optional
        ** 'price', 'quantity_break_start', 'quantity_break_end' can be of any type that supported by decimal.Decimal()
    """
    if not os.path.exists('./catalog/stock_data'):
        os.mkdir('./catalog/stock_data')
    
    inventory_data = {}
    inventory_file = './catalog/stock_data/inventory-bro.txt'
    
    download_data = True
    if os.path.exists(inventory_file):
        # Check that inventory file is no more than 1 day old
        filestat = os.stat(inventory_file)
        tm = datetime.datetime.fromtimestamp(filestat.st_mtime)
        today = datetime.datetime.now()
        dt = today - tm
        if dt.days < 1:
            download_data = False
    
    if download_data:
        # Get inventory data from ftp site
        from ftplib import FTP_TLS
        print 'Downloading inventory-bro.txt ....'
        ftps = FTP_TLS('ftp.appareldownload.com')
        ftps.login('Br0d3r', 'Br0d3r2oll')
        ftps.prot_p()
        #ftps.retrlines('LIST')
        ftps.retrbinary('RETR inventory-bro.txt', open(inventory_file, 'wb').write)
        ftps.quit()
    
    print "Parse inventory-bro.txt ... "
    first_row = None
    for row in csv.reader(open(inventory_file, 'rb')):
        itemRef = row[4].lower()
        if itemRef == 'style number':
            # save first row to be used as column header
            first_row = row
            continue
        
        source_attribs = [{'attribute_type': 'source', 'attribute_value': 'broderbros'}]
        
        inventory_data.setdefault(itemRef, [])
        
        color = row[8].lower()
        size = row[10].lower()
        
        # Warehouses starts at column 13
        for i in range(13, len(first_row)):
            wh_name = first_row[i]
            options = [
                {'option_type': 'color', 'option_value': color, 'attributes': []},
                {'option_type': 'size', 'option_value': size, 'attributes': []},
                {'option_type': 'warehouse', 'option_value': wh_name, 'attributes': source_attribs, 'shared': True},
                {'option_type': 'vendor', 'option_value': 'broderbros', 'attributes': source_attribs, 'shared': True},
            ]
            inventory_data[itemRef].append({'options': options, 'inventory': row[i]})
    
    # Pricing data
    pricing_tarfile = "./catalog/stock_data/bro-AllStyles_R06.tar.gz"
    download_data = True
    if os.path.exists(pricing_tarfile):
        # Check that file is no more than 1 day old
        filestat = os.stat(pricing_tarfile)
        tm = datetime.datetime.fromtimestamp(filestat.st_mtime)
        today = datetime.datetime.now()
        dt = today - tm
        if dt.days < 1:
            download_data = False
    
    if download_data:
        print 'Downloading items.csv for price data ....'
        br = utils.create_browser(1, 2)
        br.open("https://www.broderbros.com/cgi-bin/online/webbro/bro-index.w")
        try:
            # Fill login form
            br.select_form(name = 'frmLogin')
            frm = br.form
            
            ctrl = frm.find_control('userName')
            ctrl.value = USERNAME
            ctrl = frm.find_control('password')
            ctrl.value = PASSWORD
            
            # Submit login form
            if TESTRUN: print 'Submit Login Form'
            
            br.select_form(name = 'frmLogin')
            br.submit()
        except:
            print "Login form does not exist, please check URL, downloaded html or site is down"
            return None
#.........这里部分代码省略.........
开发者ID:satyandrab,项目名称:small_f_projects,代码行数:103,代码来源:broderbros.py

示例10: retrieveFtplib

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
def retrieveFtplib(filename, compression = None, usecols=None, dtype=None, toPrint = False, sep="\t"):
    """
    function that connects to the remote FTP serveur and extract a pandas dataframe
    the downloaded file must contain a csv file.
    It can be bz2, gz encoded or not encoded at all
    if it is encoded, the right extension must be present in the name
    -- IN
    filename : the filename with its extension to be downloaded from the remote ftp server (string)
    compression : string that specifies the encoding of the file (string in [None,"gz","bz2"] default: None
    usecols : an array containing the name of the column to extract (string[]) default: None
    dtype : a dictionary containing the name of the columns and the type to cast them ({string:string}) default: None
    toPrint : boolean that settles if the function should print its progress and results (boolean) default: False
    -- OUT
    db : a pandas dataframe containing the remote database (pandas.Dataframe)
    return None when an error occurs
    """
    startTime = time.time()
    if toPrint:
        print "==========================================="
        print "=== Connection to the remote FTP server ==="
        print "==========================================="
        print ""
        print "using ftplib"
        print "loading :",filename
        print "" 
    ftp = FTP_TLS()
    # retrieving information about account on ftp server
    (user, password, host, port) = getAccount()
    if user==None:
        print "error : coudn't read the account information"
        return None
    # connecting and logging in
    try:
        ftp.connect(host,port)
        ftp.login(user,password)
    except:
        print "error : unable to connect to the ftp server"
        return None
    # establishing the security protocol
    ftp.prot_p()
    if toPrint:
        print "connected to the FTP server"
    # retrieving the remote file as a binary file
    sio = StringIO.StringIO()
    def handle_binary(more_data):
        sio.write(more_data)
    try:
        ftp.retrbinary("RETR "+filename, callback=handle_binary)
    except:
        print "error : non-existing file :",filename
        return None
    # Go back to the start of the binary file
    sio.seek(0) 
    interval = time.time() - startTime
    if toPrint:
        print 'Data downloaded :', interval, 'sec'
    
    # Unziping the file
    if compression!=None:
        if compression=="gz":
            try:
                results = gzip.GzipFile(fileobj=sio)
            except:
                print "error : decompression impossible : not a gzip file"
                return None
            if toPrint:
                interval = time.time() - startTime
                print 'Decompression done :', interval, 'sec'
        elif compression=="bz2":
            results = StringIO.StringIO()
            a = bz2.decompress(sio.read())
            results.write(a)
            results.seek(0)
            try:
                pass
            except:
                print "error : decompression impossible : not a bz2 file"
                return None
            if toPrint:
                interval = time.time() - startTime
                print 'Decompression done :', interval, 'sec'
    else:
        results = sio
    # extracting the file into a pandas dataframe
    try:
        db = pd.read_csv(results,sep=sep, usecols = usecols)
    except:
        print "error : the file doesn't not contain a proper Dataframe"
        return None
    sio.close()
    interval = time.time() - startTime 
    if toPrint:
        print 'Dataframe created :', interval, 'sec'
    return db
开发者ID:KevinBienvenu,项目名称:RiskAnalyticsPerso,代码行数:96,代码来源:FTPTools.py

示例11: FTPClient

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

#.........这里部分代码省略.........
        Raises:
           event: ftp_before_download_file
           event: ftp_after_download_file    

        """

        try:

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_ftp_downloading_file', remote_path), self._mh.fromhere())

            if (not self._is_connected):
                self._mh.demsg('htk_on_warning', self._mh._trn.msg(
                    'htk_ftp_not_connected'), self._mh.fromhere())
                return False

            ev = event.Event(
                'ftp_before_download_file', remote_path, local_path)
            if (self._mh.fire_event(ev) > 0):
                remote_path = ev.argv(0)
                local_path = ev.argv(1)

            if (local_path != None and not path.exists(local_path)):
                self._mh.demsg('htk_on_error', self._mh._trn.msg(
                    'htk_ftp_unknown_dir', local_path), self._mh.fromhere())
                return False

            filename = remote_path.split('/')[-1]
            lpath = filename if (local_path == None) else path.join(
                local_path, filename)

            if (ev.will_run_default()):
                with open(lpath, 'wb') as f:
                    self._client.retrbinary('RETR ' + remote_path, f.write)

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_ftp_file_downloaded'), self._mh.fromhere())
            ev = event.Event('ftp_after_download_file')
            self._mh.fire_event(ev)

            return True

        except all_errors as ex:
            self._mh.demsg(
                'htk_on_error', 'error: {0}'.format(ex), self._mh.fromhere())
            if (path.exists(lpath)):
                remove(lpath)
            return False

    def upload_file(self, local_path, remote_path=None):
        """Method uploads file to server

        Args:
           local_path (str): local path
           remote_path (str): remote path, default ./filename

        Returns:
           bool: result

        Raises:
           event: ftp_before_upload_file
           event: ftp_after_upload_file    

        """

        try:
开发者ID:hydratk,项目名称:hydratk-lib-network,代码行数:70,代码来源:ftp_client.py

示例12: FTP_TLS

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

ftps = FTP_TLS(host='52.74.191.39', user='ubuntu', passwd='', keyfile='lx_sg1.pem', timeout=10)
ftps.login()           # login anonymously before securing control channel
ftps.prot_p()          # switch to secure data connection.. IMPORTANT! Otherwise, only the user and password is encrypted and not all the file data.
ftps.retrlines('LIST')

filename = 'remote_filename.bin'
print 'Opening local file ' + filename
myfile = open(filename, 'wb')

ftps.retrbinary('RETR %s' % filename, myfile.write)

ftps.close()

开发者ID:blugraph,项目名称:bgbar,代码行数:16,代码来源:nftp.py

示例13: print

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
    # TODO solve the encryption problem
    #ftps.prot_p()
    #define default DIR
    d = 'feeds'
    #Change to default DIR
    ftps.cwd(d)
    #Build list of files on servers
    l = ftps.nlst()
    l.sort()
    for i in l:
        print(i)
    #Assign last element to var
    litem = len(l)-1
    print("MOST RECENT FILE ON SERVER IS; ",l[litem])

    g = l[litem]
    #Define local file
    t = d + '/' + g
    if os.path.exists(t):
        print("FILE" ,g," EXISTS,WILL NOT DOWNLOAD FROM HOST:",host)
    else:
        print("WILL DOWNLOAD FILE:",g)
        #Construct 'RETR' string for FTP download function
        getstring = 'RETR ' + g
        print(getstring)
        ftps.retrbinary(getstring,open(t,'wb').write)
    #Close Session
    ftps.close()
except IOError as err:
    print("ERROR RETRIEVING FILES ",err)
开发者ID:yaowenqiang,项目名称:python,代码行数:32,代码来源:ftp.py

示例14: len

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
# Get list of items in current directory
directory_list = ftps.nlst()
# Get list of images
image_list = [item for item in directory_list if '.jpg' in item]
# Save oldest & newest images
images_to_upload = []
if image_list:
    # Add first image
    images_to_upload.append(image_list[0])
    if len(image_list) > 1:
        # Add last image (if more than 1 image)
        images_to_upload.append(image_list[len(image_list)-1])
    # Download oldest & newest image
    for image in images_to_upload:
        print 'Downloading %s...' % image
        ftps.retrbinary('RETR %s' % image, open(image, 'wb').write)

# Check if directory for old images exists, if not create it
if 'old' not in directory_list:
    print 'Creating dir "old"...'
    ftps.mkd('old')

# Move checked images to old
for image in image_list:
    #date_str = image.split('_')[1].split('.')[0]
    #img_date = datetime.strptime(date_str, '%Y%m%d-%H%M%S')
    print 'Moving %s to "old"...' % image
    ftps.rename(image, 'old/%s' % image)

# Disconnect from FTP server
ftps.quit()
开发者ID:MarkVLK,项目名称:GroupMe-Notifier,代码行数:33,代码来源:GroupMeNotify.py

示例15: FTP_TLS

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import retrbinary [as 别名]
import sys,json
server = json.loads(sys.argv[1])

try:
	if server['secure'] == True:
		from ftplib import FTP_TLS
		ftp = FTP_TLS()
	else:
		from ftplib import FTP
		ftp = FTP()
	ftp.connect(server['host'], server['port'])
	ftp.login(server['user'], server['pass'])
	ftp.retrbinary('RETR %s' % sys.argv[2], open(sys.argv[3], 'wb').write)
	ftp.quit()
except:
	sys.exit(1)
开发者ID:JBOCD,项目名称:JBOCD_MODULES,代码行数:18,代码来源:get.py


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