import paramiko,os,glob,time N='flow-forensics-2026-10'; R=f'/opt/apps/rl-trading-nifty/results/research/{N}'; L='/workspace/research/flow-forensics-2026-10' c=paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('187.127.176.216',username='root',key_filename='/home/box/.ssh/vps_aitrade',timeout=25) def run(cmd): i,o,e=c.exec_command(cmd); out=o.read().decode()+e.read().decode(); print(out); return out ts=time.strftime('%Y%m%d-%H%M%S') # back up anything already there (outside the served folder) run(f'if [ -e {R} ]; then mkdir -p /opt/apps/rl-trading-nifty/backups && tar czf /opt/apps/rl-trading-nifty/backups/{N}.{ts}.tgz -C {os.path.dirname(R)} {N} && echo backed-up; else echo new-folder; fi') run(f'mkdir -p {R}/charts {R}/results {R}/scripts') s=c.open_sftp(); n=0 s.put(f'{L}/index.html',f'{R}/index.html'); n+=1 for sub,pat in [('charts','*.png'),('results','*'),('scripts','*.py')]: for f in glob.glob(f'{L}/{sub}/{pat}'): if os.path.isfile(f): s.put(f,f'{R}/{sub}/'+os.path.basename(f)); n+=1 s.put(f'{L}/scripts/index.html',f'{R}/scripts/index.html'); n+=1 run(f'mkdir -p {R}/lows/charts {R}/lows/results {R}/lows/scripts') for sub,pat in [('charts','*.png'),('results','*'),('scripts','*')]: for f in glob.glob(f'{L}/lows/{sub}/{pat}'): if os.path.isfile(f): s.put(f,f'{R}/lows/{sub}/'+os.path.basename(f)); n+=1 s.close(); print('uploaded',n) run(f'chmod -R a+rX {R}; du -sh {R}') for u in ['','charts/heatmap_contrib.png','results/index.html','results/daily_summary.csv','scripts/index.html','lows/charts/lows_windows.png','lows/results/index.html','lows/results/lows_summary.csv','lows/scripts/index.html']: run(f'curl -sk -o /dev/null -w "%{{http_code}} {u}\\n" --max-time 15 --resolve aitradeanalytics.tech:443:127.0.0.1 https://aitradeanalytics.tech/rl-trading/research/{N}/{u}')