import paramiko, tarfile, io, os, sys sys.stdout.reconfigure(encoding='utf-8', errors='replace') c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15) sftp = c.open_sftp() def run(label, cmd, timeout=30): print(f'[{label}]') _, o, _ = c.exec_command(cmd, timeout=timeout) print(o.read().decode('utf-8','replace').strip()[:300]) dist = 'C:/GUARDiA/workspace/guardia-manager/dist' buf = io.BytesIO() with tarfile.open(fileobj=buf, mode='w:gz') as tar: for root, dirs, files in os.walk(dist): dirs[:] = [d for d in dirs if d not in ('.git', 'node_modules')] for fn in files: fp = os.path.join(root, fn) tar.add(fp, arcname=os.path.relpath(fp, dist)) buf.seek(0) sftp.putfo(buf, '/tmp/mgr_new.tar.gz') print('전송 완료') run('www 배포', 'mkdir -p /var/www/manager && cd /var/www/manager && tar -xzf /tmp/mgr_new.tar.gz && rm /tmp/mgr_new.tar.gz && stat index.html 2>/dev/null | grep Modify') run('재시작', 'systemctl restart guardia-manager && sleep 3 && systemctl is-active guardia-manager') sftp.close(); c.close() print('완료')