0

I want to transfer mutiple files on single sftp connection from a folder, where new files are continuously generating, through shell script.

I'm taking approach from this answer using heredocs but failed.

Loop inside "heredoc" in shell scripting

Something like this below code

sftp -P 8922 <server> <<EOF
while [[ true ]]
do
   listOfFiles=$(ls -1)

   if [[ ! -z $listOfFiles ]]
   then
         put * /somedir
   fi
done
EOF

How can i achieve this?

Dark Matter
  • 300
  • 2
  • 15

1 Answers1

2

sftp is not a shell, it doesn't execute scripts like this.

You need to execute a script that prints all the put commands, and pipe it to sftp.

for i in *
do
    echo "put $i /somedir"
done | sftp -P 8922 <server>
Barmar
  • 741,623
  • 53
  • 500
  • 612