Exemple #1
0
 def get_file(self, filename, out=None):
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     getvalue = False
     if out is None:
         out = StringIO()
         getvalue = True
     try:
         self.con.retrbinary('RETR ' + filename, out.write)
     except Exception as e:
         msg = str(e)
         if msg[:4] != '550 ':
             self.log_buffer.append(e)
         return None
     if getvalue:
         return out.getvalue()
     return out
Exemple #2
0
 def get_file(self, filename, out=None):
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     getvalue = False
     if out is None:
         out = StringIO()
         getvalue = True
     try:
         self.con.retrbinary('RETR ' + filename, out.write)
     except Exception as e:
         msg = str(e)
         if msg[:4] != '550 ':
             self.log_buffer.append(e)
         return None
     if getvalue:
         return out.getvalue()
     return out
Exemple #3
0
 def upload_file(self, filename, src, mkdir=False):
     if isinstance(src, string_types):
         if PY2:
             src = StringIO(src)
         else:
             src = BytesIO(src.encode('utf-8'))
     if mkdir:
         directory = posixpath.dirname(filename)
         if directory:
             self.mkdir(directory, recursive=True)
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     try:
         self.con.storbinary('STOR ' + filename, src, blocksize=32768)
     except FTPError as e:
         self.log_buffer.append(str(e))
         return False
     return True
Exemple #4
0
 def append(self, filename, data):
     if not isinstance(filename, text_type):
         filename = filename.decode('utf-8')
     input = StringIO(data)
     try:
         self.con.storbinary('APPE ' + filename, input)
     except Exception as e:
         self.log_buffer.append(str(e))
         return False
     return True
Exemple #5
0
 def get_file(self, filename, out=None):
     if not isinstance(filename, text_type):
         filename = filename.decode("utf-8")
     getvalue = False
     if out is None:
         if PY2:
             out = StringIO()
         else:
             out = BytesIO()
         getvalue = True
     try:
         self.con.retrbinary("RETR " + filename, out.write)
     except FTPError as e:
         msg = str(e)
         if msg[:4] != "550 ":
             self.log_buffer.append(e)
         return None
     if getvalue:
         if PY2:
             return out.getvalue()
         return out.getvalue().decode("utf-8")
     return out
Exemple #6
0
    def append(self, filename, data):
        if not isinstance(filename, text_type):
            filename = filename.decode('utf-8')

        if PY2:
            input = StringIO(data)
        else:
            input = BytesIO(data.encode('utf-8'))

        try:
            self.con.storbinary('APPE ' + filename, input)
        except FTPError as e:
            self.log_buffer.append(str(e))
            return False
        return True