Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python3
from glob import glob
import os
session_files = glob(os.environ["HOME"] + "/.putty/sessions/*")
out_file = open("putty-sessions.reg", "w")
header = '''Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions]
'''
out_file.write(header)
for fpath in session_files:
f = open(fpath, "r")
lines = f.readlines()
fname = fpath.split('/')[-1]
out_file.write("\n[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\%s]\n" % fname)
for line in lines:
data = line.split("=")
key = data[0]
val = data[1].strip()
out_file.write("\"%s\"=" % key)
try:
int(val)
out_file.write("dword:%s\n" % val.zfill(8))
except:
out_file.write("\"%s\"\n" % val)
f.close()
out_file.close()
@ezr

This comment has been minimized.

Copy link
Owner Author

@ezr ezr commented Mar 24, 2020

This is a python script that you can run on a linux system whose putty sessions are saved under ~/.putty/sessions/. The purpose is to migrate the info into a .reg file which can be imported on windows.

Very lightly tested. USE AT YOUR OWN RISK. If anyone attempts to use this then make sure to back up the registry keys on windows before making any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment