title: bash script to upload files to sftp
body: <p>I'm looking to create a smart script to upload files to an sftp site. I cannot use scp because i have no control of the sftp site plus the vendor doesn't allow public key authentication. </p>
  
  <pre><code>#!/bin/bash
  
              read -p "Do you want to list the sftp site contents (y/n): " list
              read -p "Upload Selected file, type the name of the file: " uploadfilename
  
  
      conenctsfttp() {
              export SSHPASS=****
              sshpass -e sftp -oBatchMode=no -b - testuser@example.com
      }
  
      listfiles() {
              if [[ $list = y ]];
              then
              conenctsfttp &lt;&lt;&lt; $'ls\n bye'
              else
              echo not list
              fi
      }
  
      uploadfilen() {
      #        if [[ $uploadfilename = y ]];
      #        then
              conenctsfttp &lt;&lt; EOF
              put $(uploadfilename)
      EOF
      }
  
      listfiles
      uploadfilen
  </code></pre>
  
  <p>how can i make the script read the filename and upload the file to the sftp server. The file-name is never picked up and it goes into an infinite loop. If possible i like to define a location of where files are located for the upload. </p>