diff --git a/scripts/config.json b/scripts/config.json new file mode 100644 index 00000000..208e7c97 --- /dev/null +++ b/scripts/config.json @@ -0,0 +1,24 @@ +{ + "source": { + "type": "local", + "base_dir": "public/storage", + "ssh": { + "host": "source-server.example.com", + "port": 22, + "username": "username", + "password": "your_password_here", + "key_file": "" + } + }, + "target": { + "type": "ssh", + "base_dir": "/www/wwwroot/orico-official-website/public/storage", + "ssh": { + "host": "47.91.149.172", + "port": 22, + "username": "root", + "password": "Orico666tx5d", + "key_file": "" + } + } +} diff --git a/scripts/image_migrate.py b/scripts/image_migrate.py index 0b5d8bde..cb63ff32 100755 --- a/scripts/image_migrate.py +++ b/scripts/image_migrate.py @@ -316,9 +316,9 @@ class ImageMigrator: print( f"DEBUG ensure_target_directory: 目录实际上已存在: {current_path}" ) - except: + except Exception as listdir_e: # 目录确实不存在且创建失败 - print(f"错误: 无法创建目录 {current_path}: {mkdir_e}") + print(f"错误: 无法创建目录 {current_path}: {listdir_e}") return False # 最终确认目录是否创建成功 @@ -365,7 +365,7 @@ class ImageMigrator: return True, os.path.getsize(source_path) else: if self.verbose: - print(f"DEBUG: 文件不存在!") + print("DEBUG: 文件不存在!") return False, 0 else: # SSH远程文件 @@ -388,7 +388,7 @@ class ImageMigrator: if self.source_config.is_local(): # 从本地文件复制 if self.verbose: - print(f"DEBUG read_source_file: 开始复制文件") + print("DEBUG read_source_file: 开始复制文件") print(f"DEBUG read_source_file: 源路径: {source_path}") print(f"DEBUG read_source_file: 临时路径: {temp_path}") print( @@ -401,7 +401,7 @@ class ImageMigrator: shutil.copy2(source_path, temp_path) if self.verbose: - print(f"DEBUG read_source_file: 复制完成") + print("DEBUG read_source_file: 复制完成") print( f"DEBUG read_source_file: 临时文件是否存在: {os.path.exists(temp_path)}" ) @@ -417,6 +417,8 @@ class ImageMigrator: return True except Exception as e: + with open("fails.txt", "a", encoding="utf-8") as file: + file.write(f"{source_path}\n") print(f"读取源文件失败 {source_path}: {e}") import traceback @@ -519,7 +521,7 @@ class ImageMigrator: self.target_sftp.put(temp_path, target_path) if self.verbose: - print(f"DEBUG: 上传完成") + print("DEBUG: 上传完成") except Exception as e: if self.verbose: diff --git a/scripts/images.txt b/scripts/images.txt new file mode 100644 index 00000000..f24a309d --- /dev/null +++ b/scripts/images.txt @@ -0,0 +1,2 @@ +images/banner/20251217/c16f15d090170b9cecaf6b88e02384f3_thumb.png +images/banner/20251217/c16f15d090170b9cecaf6b88e02384f3.png