本文整理汇总了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")
示例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