my $sftpHost = $userName . '@' . $hostName; use Expect; my $conn = Expect->new; $conn->raw_pty(1); $conn->log_user(0); $conn->spawn('/usr/bin/ssh', -l => $userName, $hostName, -s => 'sftp') or die "can't spawn ssh"; $conn->expect(1, "Password : "); $conn->send("$passWord\n"); $conn->expect(1, "\n"); $Net::SFTP::Foreign::debug = -1; $sftpHandl = Net::SFTP::Foreign->new(transport => $conn); die "unable to establish SSH connection: ". $sftpHandl->error if $sftpHandl->error; $sftpHandl->setcwd($destPath) or die("Cannot cd to $destPath $!\n") ; $sftpHandl->put($remtPath.$fileFnc,$fileFnc) or die("Couldn't put file in the SFTP Location $!\n");