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


Python FTP_TLS.storlines方法代码示例

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


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

示例1: write_file

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import storlines [as 别名]
 def write_file(self):
   output = open('chan_output.htm', 'w')
   for channel in self.main.channels:
     self.logger.log(LOG_DEBUG, "Writing output for %s, topic %s" % (channel, self.topics[channel]))
     output.write("<b>Channel:</b> %s\n<br /><b>Topic:</b> %s\n<br /><b>Users:</b>\n<ul>\n" % (channel, self.topics[channel]))
     for user in self.main.channels[channel]['users']:
       output.write("  <li>%s</li>\n" %(user))
     output.write("</ul>\n\n")
   output.close
   
   output = open('chan_output.htm', 'r')
   self.update_all = 0
   ftp_server = 'whub25.webhostinghub.com'
   ftp_user = '[email protected]'
   passfile = open('password.txt','r')
   password = passfile.readline()
   passfile.close()
   password = password.rstrip('\n')
   self.logger.log(LOG_INFO, "Connecting to FTP server %s, username %s" % (ftp_server, ftp_user))
   ftp = FTP_TLS(ftp_server, ftp_user, password)
   ftp.prot_p()
   self.logger.log(LOG_INFO, "Successfully logged in, storing file")
   ftp.storlines('STOR chan_output.htm', output)
   ftp.close()
   output.close()
   self.update_all = 0
   self.logger.log(LOG_INFO, "Done")
开发者ID:tntexplosivesltd,项目名称:modbot_plugins,代码行数:29,代码来源:live_stats.py

示例2: storeFtplib

# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import storlines [as 别名]
def storeFtplib(dataframe, filename="cameliaBalAGKevin.csv", compression = None, toPrint = False):
    """
    function that connects to the remote FTP serveur and upload a pandas dataframe
    the upload file must be a pandasDataframe and will be written in a csv file.
    It can be uploaded as a bz2, gz encoded or not encoded at all
    if it is encoded, the right extension must be present in the name
    -- IN
    dataframe : the dataframe to upload (pandas.Dataframe)
    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
    toPrint : boolean that settles if the function should print its progress and results (boolean) default: False
    -- OUT
    flag : boolean that settles if everything was successful (True: no problem, False: an error occured)
    """
    startTime = time.time()
    if toPrint:
        print ""
        print ""
        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 False
    # connecting and logging in
    try:
        ftp.connect(host,port)
        ftp.login(user,password)
    except:
        print "error : unable to connect to the ftp server"
        return False
    # establishing the security protocol
    ftp.prot_p()
    if toPrint:
        print "connected to the FTP server"
    try:
        lines = dataframe.to_csv(path_or_buff = None,sep="\t",columns=dataframe.columns)
    except:
        print "error : impossible to convert the dataframe into csv lines"
        return False
    sio = StringIO.StringIO(lines)
    ftp.storlines(cmd="STOR "+filename, fp=sio)
#     try:
#         ftp.storlines(cmd="STOR "+filename, file=lines)
#     except:
#         print "error : impossible to upload the file"
#         return False
    interval = time.time() - startTime 
    if toPrint:
        print 'Dataframe uploaded :', interval, 'sec'
    return True
    
开发者ID:KevinBienvenu,项目名称:RiskAnalyticsPerso,代码行数:60,代码来源:FTPTools.py


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