Why dont you just use the scripts from sources like sborg and rleech ??
They are basically what you are asking for are they not ?