基础本地测试通过,shell改进
This commit is contained in:
@@ -1,218 +1,417 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import cmd
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import base64
|
||||
from typing import Dict, Any, List
|
||||
import argparse
|
||||
import readline
|
||||
from typing import List, Optional, Tuple
|
||||
from src.file import FileHandler
|
||||
from src.network import TCPIPv6Transporter
|
||||
from src.rsa import RSACryptoManager
|
||||
import logging
|
||||
import threading
|
||||
from enum import Enum
|
||||
|
||||
class FileTransferShell:
|
||||
# 配置日志
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Color:
|
||||
"""颜色定义"""
|
||||
GREEN = '\033[92m'
|
||||
BLUE = '\033[94m'
|
||||
YELLOW = '\033[93m'
|
||||
RED = '\033[91m'
|
||||
PURPLE = '\033[95m'
|
||||
CYAN = '\033[96m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
END = '\033[0m'
|
||||
|
||||
class MenuOption(Enum):
|
||||
"""菜单选项"""
|
||||
SEND_FILE = 1
|
||||
RECEIVE_FILE = 2
|
||||
STOP_RECEIVER = 3
|
||||
STATUS = 4
|
||||
GENERATE_KEYS = 5
|
||||
FILE_INFO = 6
|
||||
EXIT = 7
|
||||
|
||||
class TCPFileShell(cmd.Cmd):
|
||||
intro = f"""
|
||||
{Color.BOLD}{Color.CYAN}╔══════════════════════════════════════════════════════╗
|
||||
║{'':^54}║
|
||||
║{Color.GREEN}🌐 TCP IPv6 文件传输工具 Shell{Color.CYAN}{'':24}║
|
||||
║{'':^54}║
|
||||
║{Color.YELLOW} 安全 • 高效 • 易用{Color.CYAN}{'':28}║
|
||||
║{'':^54}║
|
||||
╚══════════════════════════════════════════════════════╝{Color.END}
|
||||
|
||||
{Color.BLUE}请输入数字选择操作:{Color.END}
|
||||
"""
|
||||
prompt = f'{Color.BOLD}{Color.GREEN}tcpfile>{Color.END} '
|
||||
|
||||
def __init__(self):
|
||||
self.process = None
|
||||
self.start_main_process()
|
||||
super().__init__()
|
||||
self.transporter = TCPIPv6Transporter()
|
||||
self.current_file: Optional[str] = None
|
||||
self.current_file_handler: Optional[FileHandler] = None
|
||||
self.use_rich_display = self._check_rich_available()
|
||||
|
||||
def start_main_process(self):
|
||||
"""启动主程序进程"""
|
||||
def _check_rich_available(self):
|
||||
"""检查是否可用rich库"""
|
||||
try:
|
||||
self.process = subprocess.Popen(
|
||||
[sys.executable, "main.py"],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
bufsize=1
|
||||
)
|
||||
print("✓ 文件传输系统已启动")
|
||||
except Exception as e:
|
||||
print(f"✗ 启动失败: {e}")
|
||||
sys.exit(1)
|
||||
import rich
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
def send_command(self, command: str, args: Dict[str, Any] = None) -> Dict[str, Any]:
|
||||
"""发送命令到主程序"""
|
||||
if args is None:
|
||||
args = {}
|
||||
|
||||
def _print_header(self, title: str):
|
||||
"""打印标题"""
|
||||
print(f"\n{Color.BOLD}{Color.CYAN}╔{'═' * 60}╗")
|
||||
print(f"║ {Color.GREEN}{title:<59}{Color.CYAN}║")
|
||||
print(f"╚{'═' * 60}╝{Color.END}\n")
|
||||
|
||||
def _print_success(self, message: str):
|
||||
"""打印成功信息"""
|
||||
print(f"{Color.GREEN}✓ {message}{Color.END}")
|
||||
|
||||
def _print_error(self, message: str):
|
||||
"""打印错误信息"""
|
||||
print(f"{Color.RED}✗ {message}{Color.END}")
|
||||
|
||||
def _print_warning(self, message: str):
|
||||
"""打印警告信息"""
|
||||
print(f"{Color.YELLOW}⚠ {message}{Color.END}")
|
||||
|
||||
def _print_info(self, message: str):
|
||||
"""打印信息"""
|
||||
print(f"{Color.BLUE}ℹ {message}{Color.END}")
|
||||
|
||||
def _print_progress(self, current: int, total: int, prefix: str = ""):
|
||||
"""打印进度条"""
|
||||
percent = (current / total) * 100
|
||||
bar_length = 30
|
||||
filled_length = int(bar_length * current // total)
|
||||
bar = f"{Color.GREEN}{'█' * filled_length}{Color.YELLOW}{'░' * (bar_length - filled_length)}{Color.END}"
|
||||
print(f"\r{prefix} {bar} {percent:.1f}% ({current}/{total})", end='', flush=True)
|
||||
if current == total:
|
||||
print()
|
||||
|
||||
def _input_with_prompt(self, prompt: str, default: str = "") -> str:
|
||||
"""带提示的输入"""
|
||||
return input(f"{Color.BOLD}{Color.CYAN}{prompt}{Color.END} ").strip() or default
|
||||
|
||||
def _wait_for_seconds(self, seconds: int, message: str = "等待中"):
|
||||
"""等待指定秒数"""
|
||||
for i in range(seconds, 0, -1):
|
||||
print(f"\r{message} {i}秒...", end='', flush=True)
|
||||
time.sleep(1)
|
||||
print("\r" + " " * 50 + "\r", end='', flush=True)
|
||||
|
||||
def _show_main_menu(self):
|
||||
"""显示主菜单"""
|
||||
print(f"\n{Color.BOLD}{Color.PURPLE}主菜单:{Color.END}")
|
||||
print(f"{Color.CYAN}1.{Color.END} 发送文件")
|
||||
print(f"{Color.CYAN}2.{Color.END} 接收文件")
|
||||
print(f"{Color.CYAN}3.{Color.END} 停止接收器")
|
||||
print(f"{Color.CYAN}4.{Color.END} 查看状态")
|
||||
print(f"{Color.CYAN}5.{Color.END} 生成密钥对")
|
||||
print(f"{Color.CYAN}6.{Color.END} 查看文件信息")
|
||||
print(f"{Color.CYAN}7.{Color.END} 退出")
|
||||
print(f"{Color.YELLOW}{'─' * 40}{Color.END}")
|
||||
|
||||
def _get_menu_choice(self) -> Optional[MenuOption]:
|
||||
"""获取菜单选择"""
|
||||
try:
|
||||
command_data = {
|
||||
"command": command,
|
||||
"args": args
|
||||
}
|
||||
|
||||
self.process.stdin.write(json.dumps(command_data) + '\n')
|
||||
self.process.stdin.flush()
|
||||
|
||||
response_line = self.process.stdout.readline().strip()
|
||||
if not response_line:
|
||||
return {"success": False, "message": "无响应", "data": None}
|
||||
|
||||
return json.loads(response_line)
|
||||
|
||||
except Exception as e:
|
||||
return {"success": False, "message": f"通信错误: {e}", "data": None}
|
||||
choice = self._input_with_prompt("请选择操作 (1-7):")
|
||||
return MenuOption(int(choice))
|
||||
except (ValueError, TypeError):
|
||||
self._print_error("无效的选择,请输入1-7的数字")
|
||||
return None
|
||||
|
||||
def print_result(self, result: Dict[str, Any]):
|
||||
"""美化打印结果"""
|
||||
if result["success"]:
|
||||
print(f"✓ {result['message']}")
|
||||
if result["data"]:
|
||||
print("数据详情:")
|
||||
print(json.dumps(result["data"], indent=2, ensure_ascii=False))
|
||||
else:
|
||||
print(f"✗ {result['message']}")
|
||||
print()
|
||||
|
||||
def send_file_interactive(self):
|
||||
"""交互式文件发送"""
|
||||
print("\n=== 文件发送模式 ===")
|
||||
def _send_file_interactive(self):
|
||||
"""交互式发送文件"""
|
||||
self._print_header("📤 发送文件")
|
||||
|
||||
# 获取文件路径
|
||||
file_path = input("请输入要发送的文件路径: ").strip()
|
||||
if not os.path.exists(file_path):
|
||||
print("文件不存在!")
|
||||
file_path = self._input_with_prompt("请输入要发送的文件路径:")
|
||||
if not file_path or not os.path.exists(file_path):
|
||||
self._print_error("文件不存在或路径无效")
|
||||
return
|
||||
|
||||
# 获取目标地址
|
||||
target_ip = input("请输入目标IPv6地址: ").strip()
|
||||
target_port = int(input("请输入目标端口: ").strip())
|
||||
target_ip = self._input_with_prompt("请输入目标IPv6地址:", "::1")
|
||||
target_port = self._input_with_prompt("请输入目标端口:", "3141")
|
||||
|
||||
try:
|
||||
target_port = int(target_port)
|
||||
except ValueError:
|
||||
self._print_error("端口必须是数字")
|
||||
return
|
||||
|
||||
# 询问是否加密
|
||||
use_encryption = input("是否使用加密?(y/n): ").strip().lower() == 'y'
|
||||
use_encryption = self._input_with_prompt("是否使用加密? (y/n):", "n").lower() == 'y'
|
||||
public_key_path = None
|
||||
|
||||
if use_encryption:
|
||||
public_key_path = input("请输入公钥文件路径: ").strip()
|
||||
if not os.path.exists(public_key_path):
|
||||
print("公钥文件不存在!")
|
||||
public_key_path = self._input_with_prompt("请输入公钥文件路径:")
|
||||
if not public_key_path or not os.path.exists(public_key_path):
|
||||
self._print_error("公钥文件不存在")
|
||||
return
|
||||
|
||||
# 确认发送
|
||||
print(f"\n{Color.YELLOW}发送配置:{Color.END}")
|
||||
print(f"文件: {file_path}")
|
||||
print(f"目标: [{target_ip}]:{target_port}")
|
||||
print(f"加密: {'是' if use_encryption else '否'}")
|
||||
|
||||
confirm = self._input_with_prompt("确认发送? (y/n):", "y").lower()
|
||||
if confirm != 'y':
|
||||
self._print_info("发送已取消")
|
||||
return
|
||||
|
||||
# 发送文件
|
||||
args = {
|
||||
"file_path": file_path,
|
||||
"target_ip": target_ip,
|
||||
"target_port": target_port
|
||||
}
|
||||
|
||||
if public_key_path:
|
||||
args["public_key_path"] = public_key_path
|
||||
|
||||
result = self.send_command("send_file", args)
|
||||
self.print_result(result)
|
||||
try:
|
||||
self.current_file_handler = FileHandler(file_path)
|
||||
file_data = self.current_file_handler.read_file()
|
||||
self._print_success(f"读取文件成功,大小: {len(file_data)} bytes")
|
||||
|
||||
if use_encryption and public_key_path:
|
||||
self._print_info("开始加密文件...")
|
||||
file_data = RSACryptoManager.encrypt_data(file_data, public_key_path)
|
||||
self._print_success("文件加密完成")
|
||||
|
||||
self._print_info("正在连接目标服务器...")
|
||||
self._wait_for_seconds(3, "连接中")
|
||||
|
||||
success, message = self.transporter.send_data(file_data, target_ip, target_port)
|
||||
|
||||
if success:
|
||||
self._print_success(f"文件发送成功: {message}")
|
||||
else:
|
||||
self._print_error(f"发送失败: {message}")
|
||||
|
||||
except Exception as e:
|
||||
self._print_error(f"发送文件失败: {e}")
|
||||
|
||||
def receive_file_interactive(self):
|
||||
"""交互式文件接收"""
|
||||
print("\n=== 文件接收模式 ===")
|
||||
def _receive_file_interactive(self):
|
||||
"""交互式接收文件"""
|
||||
self._print_header("📥 接收文件")
|
||||
|
||||
# 获取监听端口
|
||||
listen_port = int(input("请输入监听端口: ").strip())
|
||||
port = self._input_with_prompt("请输入监听端口:", "3141")
|
||||
try:
|
||||
port = int(port)
|
||||
except ValueError:
|
||||
self._print_error("端口必须是数字")
|
||||
return
|
||||
|
||||
# 询问是否有私钥
|
||||
use_decryption = input("是否准备解密文件?(y/n): ").strip().lower() == 'y'
|
||||
# 获取输出路径
|
||||
output_path = self._input_with_prompt("请输入文件保存路径:", f"received_file_{int(time.time())}")
|
||||
|
||||
# 询问是否解密
|
||||
use_decryption = self._input_with_prompt("是否准备解密文件? (y/n):", "n").lower() == 'y'
|
||||
private_key_path = None
|
||||
|
||||
if use_decryption:
|
||||
private_key_path = input("请输入私钥文件路径: ").strip()
|
||||
if not os.path.exists(private_key_path):
|
||||
print("私钥文件不存在!")
|
||||
private_key_path = self._input_with_prompt("请输入私钥文件路径:")
|
||||
if not private_key_path or not os.path.exists(private_key_path):
|
||||
self._print_error("私钥文件不存在")
|
||||
return
|
||||
|
||||
def receive_callback(data: bytes, client_addr: Tuple):
|
||||
client_ip, client_port = client_addr[0], client_addr[1]
|
||||
self._print_success(f"接收到 {len(data)} bytes 数据来自 [{client_ip}]:{client_port}")
|
||||
|
||||
try:
|
||||
if use_decryption and private_key_path:
|
||||
self._print_info("开始解密文件...")
|
||||
data = RSACryptoManager.decrypt_data(data, private_key_path)
|
||||
self._print_success("文件解密完成")
|
||||
|
||||
handler = FileHandler(output_path)
|
||||
saved_path = handler.save_file(data, output_path)
|
||||
self._print_success(f"文件保存成功: {saved_path}")
|
||||
|
||||
except Exception as e:
|
||||
self._print_error(f"处理接收数据失败: {e}")
|
||||
|
||||
# 启动接收器
|
||||
args = {"listen_port": listen_port}
|
||||
if private_key_path:
|
||||
args["private_key_path"] = private_key_path
|
||||
success, message = self.transporter.start_server(port, receive_callback)
|
||||
|
||||
result = self.send_command("start_receiver", args)
|
||||
self.print_result(result)
|
||||
if success:
|
||||
self._print_success(f"接收器启动成功: {message}")
|
||||
print(f"\n{Color.YELLOW}接收器正在端口 {port} 监听...{Color.END}")
|
||||
print(f"{Color.CYAN}按 Ctrl+C 返回主菜单停止接收{Color.END}")
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
self.transporter.stop_server(port)
|
||||
self._print_info("接收已停止")
|
||||
else:
|
||||
self._print_error(f"启动接收器失败: {message}")
|
||||
|
||||
def _stop_receiver_interactive(self):
|
||||
"""交互式停止接收器"""
|
||||
self._print_header("⏹️ 停止接收器")
|
||||
|
||||
if result["success"]:
|
||||
print(f"接收器已在端口 {listen_port} 启动,等待文件传输...")
|
||||
print("输入 'stop' 停止接收器")
|
||||
|
||||
def stop_receiver_interactive(self):
|
||||
"""停止接收器"""
|
||||
port = int(input("请输入要停止的端口: ").strip())
|
||||
result = self.send_command("stop_receiver", {"port": port})
|
||||
self.print_result(result)
|
||||
|
||||
def list_received_files(self):
|
||||
"""列出接收到的文件"""
|
||||
result = self.send_command("list_received_files", {})
|
||||
self.print_result(result)
|
||||
|
||||
def save_received_file(self):
|
||||
"""保存接收到的文件"""
|
||||
file_id = input("请输入文件ID: ").strip()
|
||||
save_path = input("请输入保存路径: ").strip()
|
||||
ports = self.transporter.get_listening_ports()
|
||||
if not ports:
|
||||
self._print_info("当前没有运行的接收器")
|
||||
return
|
||||
|
||||
# 检查是否有私钥
|
||||
private_key_path = None
|
||||
use_decryption = input("是否使用私钥解密?(y/n): ").strip().lower() == 'y'
|
||||
if use_decryption:
|
||||
private_key_path = input("请输入私钥文件路径: ").strip()
|
||||
if not os.path.exists(private_key_path):
|
||||
print("私钥文件不存在!")
|
||||
print(f"{Color.YELLOW}当前运行的接收器端口: {ports}{Color.END}")
|
||||
|
||||
port_input = self._input_with_prompt("请输入要停止的端口 (留空停止所有):")
|
||||
port = None
|
||||
|
||||
if port_input:
|
||||
try:
|
||||
port = int(port_input)
|
||||
except ValueError:
|
||||
self._print_error("端口必须是数字")
|
||||
return
|
||||
|
||||
args = {"file_id": file_id, "save_path": save_path}
|
||||
if private_key_path:
|
||||
args["private_key_path"] = private_key_path
|
||||
success, message = self.transporter.stop_server(port) if port else self.transporter.stop_all_servers()
|
||||
|
||||
result = self.send_command("get_received_file", args)
|
||||
self.print_result(result)
|
||||
if success:
|
||||
self._print_success(message)
|
||||
else:
|
||||
self._print_error(message)
|
||||
|
||||
def interactive_shell(self):
|
||||
"""交互式Shell"""
|
||||
print("=" * 60)
|
||||
print(" 文件传输系统 - 简化模式")
|
||||
print("=" * 60)
|
||||
print("可用命令:")
|
||||
print(" send - 发送文件")
|
||||
print(" receive - 启动接收器")
|
||||
print(" stop - 停止接收器")
|
||||
print(" list - 列出接收的文件")
|
||||
print(" save - 保存接收的文件")
|
||||
print(" status - 查看系统状态")
|
||||
print(" cleanup - 清理资源")
|
||||
print(" exit - 退出程序")
|
||||
print("=" * 60)
|
||||
def _show_status(self):
|
||||
"""显示状态"""
|
||||
self._print_header("📊 系统状态")
|
||||
|
||||
while True:
|
||||
ports = self.transporter.get_listening_ports()
|
||||
print(f"{Color.CYAN}监听端口:{Color.END} {ports if ports else '无'}")
|
||||
print(f"{Color.CYAN}当前文件:{Color.END} {self.current_file or '无'}")
|
||||
|
||||
if ports:
|
||||
self._print_info("有接收器正在运行中")
|
||||
else:
|
||||
self._print_info("系统空闲")
|
||||
|
||||
def _generate_keys_interactive(self):
|
||||
"""交互式生成密钥对"""
|
||||
self._print_header("🔑 生成RSA密钥对")
|
||||
|
||||
private_path = self._input_with_prompt("私钥保存路径:", "private_key.pem")
|
||||
public_path = self._input_with_prompt("公钥保存路径:", "public_key.pem")
|
||||
|
||||
# 检查目录是否存在
|
||||
for path in [private_path, public_path]:
|
||||
dir_path = os.path.dirname(path)
|
||||
if dir_path and not os.path.exists(dir_path):
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
|
||||
success, message = RSACryptoManager.generate_key_pair(private_path, public_path)
|
||||
|
||||
if success:
|
||||
self._print_success(message)
|
||||
# 验证密钥对
|
||||
if RSACryptoManager.verify_key_pair(private_path, public_path):
|
||||
self._print_success("密钥对验证成功")
|
||||
else:
|
||||
self._print_warning("密钥对验证失败")
|
||||
else:
|
||||
self._print_error(message)
|
||||
|
||||
def _show_file_info(self):
|
||||
"""显示文件信息"""
|
||||
self._print_header("📄 文件信息")
|
||||
|
||||
file_path = self._input_with_prompt("请输入文件路径:")
|
||||
if not file_path or not os.path.exists(file_path):
|
||||
self._print_error("文件不存在")
|
||||
return
|
||||
|
||||
handler = FileHandler(file_path)
|
||||
info = handler.get_file_info()
|
||||
|
||||
if info:
|
||||
print(f"\n{Color.GREEN}文件信息:{Color.END}")
|
||||
print(f"{Color.CYAN}路径:{Color.END} {info['path']}")
|
||||
print(f"{Color.CYAN}大小:{Color.END} {info['size']} bytes")
|
||||
print(f"{Color.CYAN}SHA256:{Color.END} {info['hash']}")
|
||||
print(f"{Color.CYAN}分块数:{Color.END} {info['chunks_count']}")
|
||||
print(f"{Color.CYAN}块大小:{Color.END} {info['chunk_size']} bytes")
|
||||
else:
|
||||
self._print_error("获取文件信息失败")
|
||||
|
||||
def default(self, line):
|
||||
"""处理数字菜单选择"""
|
||||
if line.strip().isdigit():
|
||||
choice = int(line.strip())
|
||||
try:
|
||||
command = input("ftp> ").strip().lower()
|
||||
|
||||
if command == "exit":
|
||||
print("再见!")
|
||||
break
|
||||
elif command == "send":
|
||||
self.send_file_interactive()
|
||||
elif command == "receive":
|
||||
self.receive_file_interactive()
|
||||
elif command == "stop":
|
||||
self.stop_receiver_interactive()
|
||||
elif command == "list":
|
||||
self.list_received_files()
|
||||
elif command == "save":
|
||||
self.save_received_file()
|
||||
elif command == "status":
|
||||
result = self.send_command("get_status", {})
|
||||
self.print_result(result)
|
||||
elif command == "cleanup":
|
||||
result = self.send_command("cleanup", {})
|
||||
self.print_result(result)
|
||||
elif command == "":
|
||||
continue
|
||||
else:
|
||||
print("未知命令,可用命令: send, receive, stop, list, save, status, cleanup, exit")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n输入 'exit' 退出程序")
|
||||
except Exception as e:
|
||||
print(f"错误: {e}")
|
||||
menu_option = MenuOption(choice)
|
||||
self._handle_menu_choice(menu_option)
|
||||
except ValueError:
|
||||
self._print_error("无效的选择,请输入1-7的数字")
|
||||
else:
|
||||
print(f"{Color.RED}未知命令: {line}{Color.END}")
|
||||
print(f"请输入1-7的数字选择菜单选项")
|
||||
|
||||
def _handle_menu_choice(self, choice: MenuOption):
|
||||
"""处理菜单选择"""
|
||||
if choice == MenuOption.SEND_FILE:
|
||||
self._send_file_interactive()
|
||||
elif choice == MenuOption.RECEIVE_FILE:
|
||||
self._receive_file_interactive()
|
||||
elif choice == MenuOption.STOP_RECEIVER:
|
||||
self._stop_receiver_interactive()
|
||||
elif choice == MenuOption.STATUS:
|
||||
self._show_status()
|
||||
elif choice == MenuOption.GENERATE_KEYS:
|
||||
self._generate_keys_interactive()
|
||||
elif choice == MenuOption.FILE_INFO:
|
||||
self._show_file_info()
|
||||
elif choice == MenuOption.EXIT:
|
||||
return self.do_exit("")
|
||||
|
||||
# 返回主菜单
|
||||
input(f"\n{Color.YELLOW}按回车键返回主菜单...{Color.END}")
|
||||
self._show_main_menu()
|
||||
|
||||
def do_exit(self, _):
|
||||
"""退出程序"""
|
||||
print(f"\n{Color.CYAN}正在清理资源...{Color.END}")
|
||||
self.transporter.stop_all_servers()
|
||||
print(f"{Color.GREEN}再见!{Color.END}")
|
||||
return True
|
||||
|
||||
def do_quit(self, _):
|
||||
"""退出程序"""
|
||||
return self.do_exit(_)
|
||||
|
||||
def do_EOF(self, _):
|
||||
"""退出程序 (Ctrl+D)"""
|
||||
print()
|
||||
return self.do_exit(_)
|
||||
|
||||
def preloop(self):
|
||||
"""程序开始前执行"""
|
||||
print(self.intro)
|
||||
self._show_main_menu()
|
||||
|
||||
def postloop(self):
|
||||
"""程序结束后执行"""
|
||||
print(f"{Color.CYAN}谢谢使用!{Color.END}")
|
||||
|
||||
def main():
|
||||
"""Shell主入口"""
|
||||
shell = FileTransferShell()
|
||||
shell.interactive_shell()
|
||||
try:
|
||||
shell = TCPFileShell()
|
||||
shell.cmdloop()
|
||||
except KeyboardInterrupt:
|
||||
print(f"\n{Color.YELLOW}程序被用户中断{Color.END}")
|
||||
except Exception as e:
|
||||
logger.error(f"程序执行错误: {e}")
|
||||
print(f"{Color.RED}程序发生错误: {e}{Color.END}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user