本文整理汇总了Python中ftplib.FTP_TLS类的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS类的具体用法?Python FTP_TLS怎么用?Python FTP_TLS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FTP_TLS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, secured=False, verbose=False):
"""Class constructor
Called when the object is initialized
Args:
secured (bool): secured FTP
verbose (bool): verbose mode
"""
self._mh = MasterHead.get_head()
self._secured = secured
if (not self._secured):
self._client = FTP()
else:
if (not(version_info[0] == 2 and version_info[1] == 6)):
self._client = FTP_TLS()
else:
raise NotImplementedError(
'Secured mode is not supported for Python 2.6')
self._verbose = verbose
if (self._verbose):
self._client.set_debuglevel(2)
示例2: send_chunks
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: doRequest
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")
示例4: __init__
def __init__(self,ftp_server,username,password,port,timeout=10,acct='', keyfile=None,certfile=None,):
FTP_TLS.__init__(self, '', '','', acct, keyfile, certfile, timeout)
self.ftp_server = ftp_server
self.username = username
self.password = password
self.port = port
self.timeout = timeout
self.ftp = None
示例5: connect
def connect(self):
self.sock = socket.create_connection((self.ftp_server, self.port), self.timeout)
self.af = self.sock.family
self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile,ssl_version=ssl.PROTOCOL_TLSv1)
self.file = self.sock.makefile('rb')
self.welcome = self.getresp()
self.login(self.username,self.password)
FTP_TLS.prot_p(self)
return self.welcome
示例6: connect
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
示例7: connect
def connect():
global ftp;
if remoteTLS:
context = ssl.create_default_context();
ftp = FTP_TLS(remoteHost, remoteUser, remotePassword, acct="", keyfile=None, certfile=None, context=context, timeout=20);
ftp.prot_p();
else:
ftp = FTP(remoteHost, remoteUser, remotePassword, 20);
print(ftp.getwelcome());
示例8: storeFtplib
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
示例9: get_file
def get_file(filename): # how do we 'stream' the file from Box to browser? using a callback!
class VMFile: # this will store the VM message as a
def __init__(self): # memory object instead of in a file (+ deleted after execution)
self.data = ""
def __call__(self,s):
self.data += s
v = VMFile()
session = FTP_TLS('ftp.box.com', box_username, box_password) # open Box
session.retrbinary('RETR recordings/' + filename, v) # add each chunk of data to memory from Box
session.close() # close Box
return v.data # return the data put back together again to be sent to browser
示例10: start
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()
示例11: test_connection
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: test_connection
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!")
)
示例13: __init__
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()
示例14: write_file
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")
示例15: ftp_backup
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