Ejemplo n.º 1
0
 def exists(self):
     if self._matched_address:
         with self.ftpc() as ftpc:
             return ftpc.path.exists(self.remote_path)
         return False
     else:
         raise FTPFileException(
             "The file cannot be parsed as an FTP path in form 'host:port/abs/path/to/file': %s"
             % self.local_file())
Ejemplo n.º 2
0
 def mtime(self):
     if self.exists():
         with self.ftpc() as ftpc:
             try:
                 # requires write access
                 ftpc.synchronize_times()
             except:
                 pass
             return ftpc.path.getmtime(self.remote_path)
     else:
         raise FTPFileException(
             "The file does not seem to exist remotely: %s" % self.file())
Ejemplo n.º 3
0
 def download(self, make_dest_dirs=True):
     with self.ftpc() as ftpc:
         if self.exists():
             # if the destination path does not exist
             if make_dest_dirs:
                 os.makedirs(os.path.dirname(self.local_path), exist_ok=True)
             try:
                 # requires write access
                 ftpc.synchronize_times()
             except:
                 pass
             ftpc.download(source=self.remote_path, target=self.local_path)
             os.sync()  # ensure flush to disk
         else:
             raise FTPFileException(
                 "The file does not seem to exist remotely: %s" % self.local_file()
             )