本文整理汇总了Python中ftplib.FTP_TLS.login方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.login方法的具体用法?Python FTP_TLS.login怎么用?Python FTP_TLS.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib.FTP_TLS
的用法示例。
在下文中一共展示了FTP_TLS.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_session_ftps
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [as 别名]
def get_session_ftps(host, login=None, password=None, port=21, auth=False, protocol=True):
"""
Creates connection with FTPS server
:param host: host of FTPS server
:param login: user's name
:param password: password for user
:param port: port of FTPS server
:param auth: if it is true sets up secure control
connection by using TLS/SSL
:param protocol: if it is true sets up secure data connection
else sets up clear text data connection
:return: FTPConnector
:type host: str
:type login: str
:type password: str
:type port: int
:type auth: bool
:type protocol: bool
:rtype: FTPConnector
"""
try:
ftp = FTP_TLS()
ftp.connect(host, port)
ftp.login(login, password)
if protocol:
ftp.prot_p()
else:
ftp.prot_c()
if auth:
ftp.auth()
return FTPConnector(ftp)
except error_perm, exp:
raise FTPConnectorError(
exp.message
)
示例2: send_chunks
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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
示例3: main
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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
示例4: sync
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例5: connect
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [as 别名]
def connect(self):
#初始化 FTP 链接
if self.ftp_ssl:
ftp = FTPS()
else:
ftp = FTP()
print('-'*20+self.ftp_name+'-'*20)
print('connect '+('ftps' if self.ftp_ssl else 'ftp')+'://'+self.ftp_host+':'+self.ftp_port)
try:
ftp.connect(self.ftp_host,self.ftp_port)
except Exception as e:
print (e)
print ('connect ftp server failed')
sys.exit()
try:
ftp.login(self.ftp_user,self.ftp_passwd)
print ('login ok')
except Exception as e:#可能服务器不支持ssl,或者用户名密码不正确
print (e)
print ('Username or password are not correct')
sys.exit()
if self.ftp_ssl:
try:
ftp.prot_p()
except Exception as e:
print (e)
print ('Make sure the SSL is on ;')
print(ftp.getwelcome())
ftp.cwd(self.ftp_webroot)
print('current path: '+ftp.pwd())
self.ftp=ftp
示例6: getfilelist
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例7: sendPackagesFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例8: sendUpdateFilesFtp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例9: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例10: connexionftp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [as 别名]
def connexionftp(adresseftp, nom, mdpasse, passif):
"""connexion au serveur ftp et ouverture de la session
- adresseftp: adresse du serveur ftp
- nom: nom de l'utilisateur enregistré ('anonymous' par défaut)
- mdpasse: mot de passe de l'utilisateur ('[email protected]' par défaut)
- passif: active ou désactive le mode passif (True par défaut)
retourne la variable 'ftplib.FTP' après connexion et ouverture de session
"""
try:
verbose('Attente connexion FTP .....')
if modeSSL:
ftp = FTP_TLS()
ftp.connect(adresseftp, 21)
ftp.login(nom, mdpasse)
ftp.prot_p()
ftp.set_pasv(passif)
else:
ftp = (ftplib.FTP(adresseftp, nom, mdpasse))
ftp.cwd(destination)
verbose ('Destination : '+destination)
verbose('Connexion FTP OK')
etat = ftp.getwelcome()
verbose("Etat : "+ etat)
return ftp
except:
verbose('Connexion FTP impossible', True)
suppressionDossierTemp(dossierTemporaireFTP)
sys.exit()
示例11: storeFtplib
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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
示例12: connect
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [as 别名]
def connect(self):
ftps = FTP_TLS(self.host)
ftps.login(self.username, self.passwd)
# switch to secure data connection..
# IMPORTANT!
# Otherwise, only the user and password is encrypted and not all the file data.
ftps.prot_p()
return ftps
示例13: start
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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()
示例14: ftpUpload
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [as 别名]
def ftpUpload(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_file = open(filename, 'rb')
ftps.storbinary('STOR '+filename, local_file)
示例15: file_ftps
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import login [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)