Factor out filenames to a helper function

I can't test this completely yet, because of the "No hosts found. Please
specify (single) host string for connection:" bug.