in reply to Net::SFTP error

Your error message means what it says: Bad file descriptor <GEN0>. That's not part of the code you posted, but I'm not sure if it's coming from your code or from a module.

Did you run the posted snippet and get that error?

Oh, and use strict;.