def test_download_fs_fs(self): # Download files from local to remote (which is empty) local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) remote = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) opts = {"force": False, "delete": False, "dry_run": False} s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 0) self.assertEqual(stats["local_files"], 0) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 4) # currently files are not counted, when inside a *new* folder self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # Again: nothing to do s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) self.assertEqual(stats["local_files"], 6) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 6) self.assertEqual(stats["files_written"], 0) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["bytes_written"], 0) # file times are preserved self.assertEqual(_get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(_get_test_file_date("remote/file1.txt"), STAMP_20140101_120000)
def test_download_fs_fs(self): # Download files from local to remote (which is empty) local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) remote = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) opts = {"force": False, "delete": False, "verbose": self.verbose} s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 0) self.assertEqual(stats["local_files"], 0) self.assertEqual(stats["remote_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["remote_files"], 4) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # Again: nothing to do s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) self.assertEqual(stats["local_files"], 6) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 6) self.assertEqual(stats["files_written"], 0) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["bytes_written"], 0) # file times are preserved self.assertEqual(get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote/file1.txt"), STAMP_20140101_120000)
def test_issue_24(self): if not self.use_ftp_target: raise SkipTest("Only FTP targets.") # empty_folder() empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) local_target = make_target(self.local_url) remote_target = make_target(self.remote_url) SIZE = 1000 * 1000 write_test_file("local/large1.txt", size=SIZE) write_test_file("remote/large2.txt", size=SIZE) opts = { "verbose": 5, "match": "large*.txt", } synchronizer = DownloadSynchronizer(local_target, remote_target, opts) assert is_test_file("local/large1.txt") assert is_test_file("remote/large2.txt") assert not is_test_file("remote/large1.txt") assert not is_test_file("local/large2.txt") synchronizer.run() # Expect that large2 was downloaded assert not is_test_file("remote/large1.txt") assert get_test_file_size("local/large2.txt") == SIZE
def sync_from_server(self): """Sync today's readings from FTP server Note: this recreates the download/upload synchronisers each time to avoid issues with flags set in these classes (bug in pyftpsync; see https://github.com/mar10/pyftpsync/issues/20) """ # current date and time now = datetime.datetime.utcnow() # FTP download options download_opts = {"force": True, "resolve": "remote", "verbose": 3, # match today's filename (wildcard required) "match": "*" + self.filename_from_date(now)} # create downloader ftp_downloader = DownloadSynchronizer(self.local_target, self.remote_target, download_opts) # download ftp_downloader.run()
def test_issue_24(self): if not self.use_ftp_target: raise SkipTest("Only FTP targets.") # empty_folder() empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) local_target = make_target(self.local_url) remote_target = make_target(self.remote_url) SIZE = 1000 * 1000 write_test_file("local/large1.txt", size=SIZE) write_test_file("remote/large2.txt", size=SIZE) opts = {"verbose": 5, "match": "large*.txt"} synchronizer = DownloadSynchronizer(local_target, remote_target, opts) assert is_test_file("local/large1.txt") assert is_test_file("remote/large2.txt") assert not is_test_file("remote/large1.txt") assert not is_test_file("local/large2.txt") synchronizer.run() # Expect that large2 was downloaded assert not is_test_file("remote/large1.txt") assert get_test_file_size("local/large2.txt") == SIZE
def test_issue_5(self): """issue #5: Unable to navigate to working directory '' (Windows)""" if not on_windows: raise SkipTest("Windows only") local = targets.FsTarget("c:/temp") remote = FtpTarget("/", "www.wwwendt.de", None, self.username, self.password) opts = {"resolve": "remote", "verbose": 3, "dry_run": True} s = DownloadSynchronizer(local, remote, opts) s.run()
def test_issue_5(self): """issue #5: Unable to navigate to working directory '' (Windows)""" if not on_windows: raise SkipTest("Windows only") local = targets.FsTarget("c:/temp") remote = FtpTarget("/", "www.wwwendt.de", None, self.username, self.password) opts = {"resolve": "remote", "verbose": 3, "dry_run": True} s = DownloadSynchronizer(local, remote, opts) s.run()
def test_issue_20(self): opts = {"verbose": 5} local_target = make_target(self.local_url) remote_target = make_target(self.remote_url) ftp_downloader = DownloadSynchronizer(local_target, remote_target, opts) ftp_uploader = UploadSynchronizer(local_target, remote_target, opts) write_test_file("local/large1.txt", size=10 * 1000) write_test_file("remote/large2.txt", size=10 * 1000) ftp_downloader.run() ftp_uploader.run()
def download_prolog(): localpath = path_config.local_ftp_path # 本地保存的ftp目录 os.makedirs(localpath, 0o777) # 创建本地日志文件夹 local = FsTarget(localpath) remote = FtpTarget(path_config.ftp_remotepath, path_config.ftp_server, username=path_config.ftp_username, password=path_config.ftp_password) opts = {"resolve": "skip", "verbose": 1} try: s = DownloadSynchronizer(local, remote, opts) # 下载ftp日志文件夹 s.run() except SyntaxError: pass