本文整理汇总了Python中ftplib.FTP_TLS.connect方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.connect方法的具体用法?Python FTP_TLS.connect怎么用?Python FTP_TLS.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib.FTP_TLS
的用法示例。
在下文中一共展示了FTP_TLS.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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()
示例2: getfilelist
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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()
示例3: connect
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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
示例4: connexionftp
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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()
示例5: get_session_ftps
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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
)
示例6: storeFtplib
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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
示例7: ftpUpload
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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)
示例8: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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"
示例9: __init__
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
class FTPS:
def __init__(self):
self.ftps = FTP_TLS( )
def connect(self):
self.ftps.connect('192.168.0.102', 2121)
print(self.ftps.getwelcome())
def login(self):
self.ftps.login('anderson', 'nosredna89')
self.ftps.prot_p() #para fazer a conexação de dados segura
def close(self):
self.ftps.close()
示例10: ftpDownload
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
def ftpDownload(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_filename = filename
with open(local_filename, 'wb') as f:
def callback(data):
f.write(data)
ftps.retrbinary('RETR %s' % filename, callback)
示例11: Push
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
def Push( FtpServer, Username, Password, uploadlist = FilesToPut, port = 21):
print >> sys.stderr, "Login to %s:%s using %s:%s"%(FtpServer, port, Username, 'xxx')
ftp = FTP()
ftps = FTP_TLS()
ftps.connect(FtpServer,Port)
ftps.auth()
ftps.login(Username, Password) # login anonymously before securing control channel
ftps.prot_p()
ftp.set_pasv(False)
for f in uploadlist:
#print "uploading %s"%f
fp = open( f, 'rb')
os.path.basename(f)
print f
ftp.storbinary("STOR,%sx " %(os.path.basename(f),fp))
#ftp.storbinary('STOR, %s',fp %(basename(f)) ) # send the file
ftp.quit()
示例12: ftp_backup
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
def ftp_backup(dmpdir,dbname):
try:
#
ftp =FTP_TLS()
ftp.connect(ftphost,ftpport)
ftp.login(ftpuser,ftppass)
ftp.prot_p()
print "Welcome:",ftp.getwelcome()
print ftp.retrlines('LIST')
# ftp =FTP()
# ftp.connect(ftphost,ftpport)
# ftp.login(ftpuser,ftppass)
# print "Welcome:",ftp.getwelcome()
# print ftp.retrlines('LIST')
except Exception,e:
print e
return
示例13: getfiles
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [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()
示例14: ftpUpload
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
def ftpUpload(filename, system):
from ftplib import FTP_TLS
import os
if os.path.isfile(filename):
zipFilename = compressit(filename, system)
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(zipFilename, 'rb')
ftps.storbinary('STOR '+zipFilename, local_file)
print "file %s has been uploaded." % zipFilename
return True
示例15: make_msg
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import connect [as 别名]
def make_msg(self, args):
# make connection
conn = None
if args.ssl or args.starttls:
conn = FTP_TLS()
conn.ssl_version = PROTOCOL_TLSv1
else:
conn = FTP()
if args.verbose:
conn.set_debuglevel(1)
conn.connect(args.host, args.port, args.timeout)
if args.starttls:
conn.auth()
conn.prot_p()
conn.login(args.user, args.password)
self.conn = conn
return args.message