示例#1
0
文件: test_ftp.py 项目: 45deg/cliboa
 def test_list_files_ok(self):
     # use public ftp
     host = "test.rebex.net"
     ftp_util = FtpUtil(host, "demo", "password")
     src_dir = "/"
     pattern = "(.*).txt"
     os.makedirs(self.__dest_dir)
     ftp_util.list_files(src_dir, self.__dest_dir, re.compile(pattern))
     exists_downloaded_file = os.path.exists(
         os.path.join(self.__dest_dir, "readme.txt"))
     shutil.rmtree(self.__dest_dir)
     assert exists_downloaded_file is True
示例#2
0
文件: test_ftp.py 项目: 45deg/cliboa
 def test_list_files_ng(self):
     # use public ftp
     host = "test.rebex.net"
     # Invalid password
     timeout = 5
     retry_count = 1
     ftp_util = FtpUtil(host, "demo", "pass", timeout, retry_count)
     src_dir = "/"
     pattern = "(.*).txt"
     os.makedirs(self.__dest_dir)
     with pytest.raises(IOError) as execinfo:
         ftp_util.list_files(src_dir, self.__dest_dir, re.compile(pattern))
     shutil.rmtree(self.__dest_dir)
     assert "FTP failed." in str(execinfo.value)
示例#3
0
    def execute(self, *args):
        # essential parameters check
        valid = EssentialParameters(
            self.__class__.__name__,
            [self._host, self._user, self._src_dir, self._src_pattern],
        )
        valid()

        os.makedirs(self._dest_dir, exist_ok=True)

        # fetch src
        ftp_util = FtpUtil(
            self._host,
            self._user,
            self._password,
            self._timeout,
            self._retry_count,
            self._port,
            self._tls,
        )
        files = ftp_util.list_files(self._src_dir, self._dest_dir,
                                    re.compile(self._src_pattern))

        if self._quit is True and len(files) == 0:
            self._logger.info(
                "No file was found. After process will not be processed")
            return StepStatus.SUCCESSFUL_TERMINATION

        # cache downloaded file names
        ObjectStore.put(self._step, files)