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


Python FTP_TLS.nlst方法代码示例

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


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

示例1: getfilelist

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

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


	ftpsconnection = FTP_TLS()
	ftpsconnection.connect(server, port)
	ftpsconnection.auth()
	ftpsconnection.prot_p()
	ftpsconnection.login(user, password)
	ftpsconnection.prot_p()

	rootfiles = ftpsconnection.nlst()

	for i in range(0,5):
		episodes = ftpsconnection.nlst(rootfiles[i])

		for episode in episodes:
			sqlitecursor.execute('''INSERT OR IGNORE INTO files VALUES ("%(date)d", "%(folder)s")''' % {'date': time.time(), 'folder': ("/" + rootfiles[i] + "/" + episode) } )
			sqliteconnection.commit()

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

示例2: sendPackagesFtp

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import nlst [as 别名]
def sendPackagesFtp():
    print "---- Send packages by FTP"
    global serverFtp
    global userFtp
    global passFtp

    from ftplib import FTP_TLS
    ftps = FTP_TLS(serverFtp)
    ftps.set_debuglevel(1)
    ftps.login(userFtp, passFtp)
    ftps.prot_p()
    try:
        ftps.sendcmd('MKD ' + '/files/' + strProductVer)
    except Exception:
        print 'Directory already exists'
    ftps.cwd('/files/' + strProductVer)
    
    filesListFtp = ftps.nlst()
    filesList = os.listdir(packagesPath)
    newFilesList = [e for e in filesList if not(e in filesListFtp)]
    
    for fileName in newFilesList:
        ftps.storbinary('STOR ' + fileName, open(packagesPath + '\\' + fileName, 'rb'))

    ftps.quit()
开发者ID:barkinet,项目名称:quite-rss.tools,代码行数:27,代码来源:prepare-install.py

示例3: main

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import nlst [as 别名]
def main():
	global ftp_client

	scan_arguments()
	ftp_client = FTP(host)

	try:
		ftp_client.login(username, password)
	except ftplib.all_errors as e:
		print "ERROR: cannot login with username '{0}' and relative password.\nMessage returned from server:".format(username)
		print e
		return

	try:
		ftp_client.cwd(remote_dir)
	except ftplib.all_errors as e:
		print "ERROR: emote directory '{0}' not existing.\nMessage returned from server:".format(remote_dir)
		print e
		return
	else:
		files = ftp_client.nlst()
		print_directory_content(files)
		setup_folder()
		download_files(remote_dir, files)
		if compress:
			create_zip(local_dir)

	try:
		ftp_client.close()
		print "!!!!! OPERATION COMPLETED SUCCESSFULLY !!!!!"
	except ftplib.all_errors as e:
		print "ERROR: cannot close the connection properly.\nMessage from server:"
		print e
开发者ID:Diiaablo95,项目名称:mirr_downloader,代码行数:35,代码来源:mirr_downloader.py

示例4: getfiles

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

示例5: get_ftp_data

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

示例6: connect

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

示例7: FTPClient

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

#.........这里部分代码省略.........
            else:
                self._client.quit()
                self._is_connected = False
                self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                    'htk_ftp_disconnected'), self._mh.fromhere())
                return True

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

    def list_dir(self):
        """Method lists remote working directory   

        Args:  
           none   

        Returns:
           list: names         

        """

        try:

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_ftp_list_dir', self._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

            names = self._client.nlst()
            if ('.' in names):
                names.remove('.')
            if ('..' in names):
                names.remove('..')

            return names

        except all_errors as ex:
            self._mh.demsg(
                'htk_on_error', 'error: {0}'.format(ex), self._mh.fromhere())
            return None

    def change_dir(self, path):
        """Method changes remote working directory

        Args:
           path (str): new remote path

        Returns:
           bool: result         

        Raises:
           event: ftp_before_change_dir        

        """

        try:

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'htk_ftp_change_dir', path), self._mh.fromhere())

            if (not self._is_connected):
开发者ID:hydratk,项目名称:hydratk-lib-network,代码行数:70,代码来源:ftp_client.py

示例8: print

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import nlst [as 别名]
    #ftps.login(user,secret)

    ftps.sendcmd('USER ' + user)
    ftps.sendcmd('PASS ' + secret)
    print(ftps.getwelcome())
    print('CURRENT WORKING DIRECTORY IS:',ftps.pwd())
    #Enable data encryption
    # 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
开发者ID:yaowenqiang,项目名称:python,代码行数:32,代码来源:ftp.py

示例9: group_listing

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import nlst [as 别名]
def group_listing():
    # Get list of groups user is a member of
    r = requests.get('%s/groups?token=%s' % (GROUPME_API_URL, TOKEN))
    resp = r.json()

    print 'Groups:'
    for item in resp['response']:
        print item['name']

# Securely connect to FTP server
ftps = FTP_TLS(HOST, USER, PASSWD)
ftps.prot_p()
# Change working directory to directory containing images
ftps.cwd(IMAGE_DIRECTORY)
# 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)
开发者ID:MarkVLK,项目名称:GroupMe-Notifier,代码行数:32,代码来源:GroupMeNotify.py

示例10: ServerWatcher

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

#.........这里部分代码省略.........
        except socket.gaierror:
            self.ftp = None
            ok = False
            msg = 'Server address could not be found.' 
        except (error_perm, error_reply):
            info = traceback.format_exception(*sys.exc_info())
            for i in info: sys.stderr.write(i)
            ok = False
            msg = error_msg 
        else:
            if '230' in loginResponse:
                ok = True
            else:
                ok = False
                msg = error_msg
        
        if ok:
            # Logged in. Now let's do compability tests.
            if not self.testPermissions():
                # User doesn't have write permissions, don't bother doing next test.
                ok = False
                msg = 'It seems like you do not have write access to this server.' 
            else:
                # 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.
开发者ID:ShareByLink,项目名称:iqbox-ftp,代码行数:70,代码来源:watchers.py


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