本文整理汇总了Python中ftplib.FTP_TLS.quit方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.quit方法的具体用法?Python FTP_TLS.quit怎么用?Python FTP_TLS.quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib.FTP_TLS
的用法示例。
在下文中一共展示了FTP_TLS.quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_chunks
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def send_chunks(self):
if self.final_chunks is None:
return ERR
if self.tls_flag:
if self.auth_flag:
ftp_obj = FTP_TLS(host=self.server, user=self.creds[0], passwd=self.creds[1])
else:
ftp_obj = FTP_TLS(host=self.server)
else:
if self.auth_flag:
ftp_obj = FTP(host=self.server, user=self.creds[0], passwd=self.creds[1])
else:
ftp_obj = FTP(host=self.server)
try:
ftp_obj.login()
sys.stdout.write("\t[+]\tConnected to server %s.\n" % self.server)
except:
sys.stderr.write("\t[-]\tCould not login to the server.\n")
return ERR
for chunk in self.final_chunks:
ftp_obj.mkd(chunk)
time.sleep(SLEEP)
ftp_obj.quit()
sys.stdout.write("\t[+]\tWrote %s(+1) folders.\n" % (len(self.final_chunks)-1))
return OKAY
示例2: sync
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例3: sendUpdateFilesFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def sendUpdateFilesFtp():
print "---- Send update files 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()
ftps.cwd('/files/updates')
ftps.storbinary('STOR ' + 'file_list.md5', open(quiterssFileRepoPath + '\\file_list.md5', 'rb'))
ftps.storbinary('STOR ' + 'VersionNo.h', open(quiterssSourcePath + '\\src\\VersionNo.h', 'rb'))
ftps.storbinary('STOR ' + 'HISTORY_EN', open(quiterssSourcePath + '\\HISTORY_EN', 'rb'))
ftps.storbinary('STOR ' + 'HISTORY_RU', open(quiterssSourcePath + '\\HISTORY_RU', 'rb'))
prepareFileList7z = []
for file in prepareFileList:
prepareFileList7z.append(file + '.7z')
for fileName in prepareFileList7z:
ftps.storbinary('STOR ' + 'windows' + fileName.replace('\\','/'), open(quiterssFileRepoPath + '\\windows' + fileName, 'rb'))
ftps.quit()
示例4: sendPackagesFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例5: getfilelist
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例6: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21, passive = False, StartTls = False ):
print "Login to %s:%s using %s:%s (%s%s)"%(FtpServer, port, Username, 'xxx',
'passive' if passive else 'active',
'/tls' if StartTls else '')
if StartTls:
ftp = FTP_TLS()
else:
ftp = FTP()
#ftp.set_debuglevel(2)
ftp.connect( FtpServer, port )
ftp.login( Username, Password ) # user anonymous, passwd [email protected]
ftp.set_pasv( passive )
if StartTls:
ftp.prot_p()
for f in uploadlist:
print "uploading %s"%f
fp = open( f, 'rb')
ftp.storbinary('STOR %s'%os.path.basename(f), fp) # send the file
ftp.quit()
示例7: doRequest
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def doRequest():
# Send the file up to the FTP server
print ("Upload picture start")
ftp = FTP_TLS('individual.utoronto.ca', 'USER','1PASS.')
file = open('data.jpg','rb') # file to send
ftp.storbinary('STOR data.jpg', file) # send the file
file.close() # close file and FTP
ftp.quit()
print ("Upload picture complete")
print ("Requesting file request")
reqUrlA = 'http://api.cloudsightapi.com/image_requests/' # get token
reqUrlB = 'http://api.cloudsightapi.com/image_responses/' # get the final recognition result with token
headers = {
'Authorization' : 'CloudSight 149xzcR0nYPrwThNXVLecQ',
}
postData = {
'image_request[remote_image_url]' : "http://individual.utoronto.ca/timlock/data.jpg",
'image_request[locale]': "en_us",
'image_request[language]': "en"
}
try:
response = requests.post(reqUrlA, headers=headers, params=postData)
except Exception, e:
print 'Error: connection error, please check your Internet and confirm the image url'
print e
return ("FAILED")
示例8: start
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例9: file_ftps
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def file_ftps(host,un,pw,ftp_filename,source_filename):
try:
ftps = FTP_TLS(host)
ftps.auth_tls()
ftps.login(un,pw)
ftps.prot_p()
ftps.storbinary("STOR " + ftp_filename, file(source_filename, "rb"))
ftps.quit()
except ftplib.all_errors, error:
print 'Error:', str(error)
logging.info(mydate+ ' - '+'FTPS Error Encountered: '+ str(error))
sys.exit(0)
示例10: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21, passive = False, StartTls = False, Sftp = False ):
print "Login to %s:%s using %s:%s (%s%s)"%(FtpServer, port, Username, 'xxx',
'passive' if passive else 'active',
'/tls' if StartTls else '')
if Sftp:
paramiko.util.log_to_file('/tmp/paramiko.log')
transport = paramiko.Transport((FtpServer,int(port)))
transport.connect(username = Username, password = Password)
sftp = paramiko.SFTPClient.from_transport(transport)
print "Uploading file"
filepath = '../php/basedata.php'
localpath = 'basedata.php'
sftp.put(filepath, localpath)
sftp.close()
transport.close()
else:
if StartTls:
ftp = FTP_TLS()
else:
ftp = FTP()
ftp.connect( FtpServer, port )
ftp.login( Username, Password)
ftp.set_pasv( passive )
if StartTls:
ftp.prot_p()
for f in uploadlist:
print "uploading %s"%f
fp = open( f, 'rb')
ftp.storbinary('STOR %s'%os.path.basename(f), fp) # send the file
ftp.quit()
if __name__ == "__main__":
if len(sys.argv) < 5:
print >> sys.stderr, "usage %s <server> <port> <username> <password>"%sys.argv[0]
exit( 1 )
FtpServer = sys.argv[1]
Port = sys.argv[2]
Username = sys.argv[3]
Passwd = sys.argv[4]
Push( FtpServer, Username, Passwd, port = Port )
print >> sys.stderr, "Done"
示例11: test_connection
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def test_connection(self, cr, uid, ids, context={}):
for ftp in self.browse(cr, uid, ids, context=context):
conn = False
try:
# Perhaps to include timeout?
conn = FTP_TLS(host=ftp.host, user=ftp.username, passwd=ftp.passwd)
except:
conn = FTP(host=ftp.host, user=ftp.username, passwd=ftp.passwd)
if not conn:
raise osv.except_osv(('Error!'), ("Connection can not be established!\nPlease, check you settings"))
conn.quit()
raise osv.except_osv(('!'), ("Connection Succeed!"))
示例12: ftp_files
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例13: test_connection
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [as 别名]
def test_connection(self, cr, uid, ids, context={}):
for ftp in self.browse(cr, uid, ids, context=context):
conn = FTP_TLS(
host=ftp.host, user=ftp.username, passwd=ftp.passwd
)
if not conn:
raise orm.except_orm(
_('Error!'),
_("Connection can not be established!\n"
"Please, check you settings")
)
conn.quit()
raise orm.except_orm(
_('!'),
_("Connection Succeed!")
)
示例14: getfiles
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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()
示例15: get_ftp_data
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import quit [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