Esempio n. 1
0
 def mkdir(self, path):
     try:
         dst_path = self._get_realpath(path)
         self._conn.mkd(dst_path)
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
     return
Esempio n. 2
0
 def list(self, path):
     """ list remote directory <path>"""
     try:
         dst_path = self._get_realpath(path)
         return self._conn.nlst(dst_path)
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 3
0
 def rename(self, oldpath, newpath):
     try:
         old_realpath = self._get_realpath(oldpath)
         new_realpath = self._get_realpath(newpath)
         self._conn.rename(old_realpath, new_realpath)
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 4
0
 def delete(self, path, filename):
     """ Delete <filename> into directory <path>"""
     try:
         dstpath = self._get_realpath(path)
         full_dstpath = self._tweaked_join(dstpath, filename)
         self._conn.delete(full_dstpath)
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 5
0
 def _connect(self):
     if self._conn is not None:
         log.warn("Already connected to ftps server")
         return
     try:
         self._conn = FTP_TLS_Data(self._host, self._user, self._passwd)
         # Explicitly ask for secure data channel
         self._conn.prot_p()
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 6
0
 def download_fobj(self, path, remotename, fobj):
     """ returns <remotename> found in <path>"""
     try:
         dstpath = self._get_realpath(path)
         dstpath = self._tweaked_join(path, remotename)
         self._conn.retrbinary("RETR {0}".format(dstpath),
                               lambda x: fobj.write(x))
         self._check_hash(remotename, fobj)
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 7
0
 def upload_fobj(self, path, fobj):
     """ Upload <data> to remote directory <path>"""
     try:
         dstname = self._hash(fobj)
         path = os.path.join(path, dstname)
         dstpath = self._get_realpath(path)
         self._conn.storbinarydata("STOR {0}".format(dstpath), fobj)
         return dstname
     except Exception as e:
         raise IrmaFTPSError("{0}".format(e))
Esempio n. 8
0
 def __init__(self,
              host,
              port,
              user,
              passwd,
              dst_user=None,
              upload_path=None):
     super(IrmaFTPS, self).__init__(host, port, user, passwd, dst_user,
                                    upload_path)
     # TODO support connection on non standard port
     if self._port != FTP_TLS.port:
         reason = ("connection supported " +
                   "only on port {0}".format(FTP_TLS.port))
         raise IrmaFTPSError(reason)
     self._connect()
Esempio n. 9
0
 def deletepath(self, path, deleteParent=False):
     # recursively delete all subdirs and files
     try:
         for f in self.list(path):
             if self.is_file(path, f):
                 self.delete(path, f)
             else:
                 self.deletepath(self._tweaked_join(path, f),
                                 deleteParent=True)
         if deleteParent:
             dstpath = self._get_realpath(path)
             self._conn.rmd(dstpath)
     except Exception as e:
         reason = "{0} [{1}]".format(e, path)
         raise IrmaFTPSError(reason)
Esempio n. 10
0
 def __init__(self,
              host,
              port,
              auth,
              key_path,
              user,
              passwd,
              dst_user=None,
              upload_path=None):
     if auth != "password":
         raise IrmaConfigurationError("key authentication not supported for"
                                      " FTPS")
     super(IrmaFTPS, self).__init__(host, port, auth, key_path, user,
                                    passwd, dst_user, upload_path)
     # TODO support connection on non standard port
     if self._port != FTP_TLS.port:
         reason = ("connection supported " +
                   "only on port {0}".format(FTP_TLS.port))
         raise IrmaFTPSError(reason)
     self._connect()