title: pass password to sftp in a bash script
body: <p>I would like to automate a bash script, that connects to server using sftp and does a file transfer. I have the password for this, and initially I tried for this</p>
  
  <pre><code>sftp $acc@$host &lt;&lt; EOF
  &lt;passwd_here&gt;
  cd $dir
  get $file
  quit
  EOF
  </code></pre>
  
  <p>but it still prompted for password, and I had to enter it manually at the prompt.</p>
  
  <p>After searching SO, I found <a href="https://stackoverflow.com/questions/5386482/how-to-run-the-sftp-command-with-a-password-from-bash-script">this post</a> which had a solution with <code>expect</code>, which I tried and I got the following error:</p>
  
  <p>Script:</p>
  
  <pre><code>sftp -b cmdfile.txt $acc@$host
  expect "Password:"
  send "&lt;passwd&gt;\n";
  interact
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Permission denied (publickey,keyboard-interactive).
  </code></pre>
  
  <p><code>cmdfile.txt</code></p>
  
  <pre><code>cd $dir
  get $file
  quit
  </code></pre>
  
  <p>Please let me know, How to connect using the password in a bash script?</p>