in reply to passwordless SFTP works from cmd line, not from modules

Start the sftp session from the command line with the flag -v and look for differences (and also post it here!).

update: On the Net::SFTP::Foreign you are actually passing a password (even if it is the empty one). That makes the module force password authentication!