How to pass an array containing file names to a sftp script?

hi,

i want to pass an array parameters to a sftp script so that i can transfer each file in the array to the remote server by connecting only once to the sftp remote server.

i thought of using a variable that contains list of file names separated by a space and pass the variable to the sftp script. but inside sftp it transfers only the last file if i use multiple file name with the mput command.

mainscript.sh

FILE_NAMES="s1.txt s2.txt s3.lst"
/home/sftp_script $FILE_NAMES

sftp_script

set FILENAME [lindex $argv 0]
spawn /usr/bin/sftp abc@ftp.sample.com
expect "abc@ftp.sample.com's password:"
send "pass\r"
expect "sftp>"
send "cd Out\r"
expect "sftp>"
send "mput $FILENAME\r"
expect "sftp>"
send "bye\r"
expect eof

the above sftp script transfers only the last file. so i thought of passing an array to the sftp script and use a single array element at a time to the mput command. i donot know if it is possible or not. i hope you have understood my requirement. can someone give a better idea please.

make your $FILE_NAMES within quotes

FILE_NAMES="s1.txt s2.txt s3.lst" 
/home/sftp_script "$FILE_NAMES"

i donot think i will work i tried hardcoding the filenames inside sftp script

spawn /usr/bin/sftp abc@ftp.sample.com
expect "abc@ftp.sample.com's password:"
send "pass\r"
expect "sftp>"
send "cd Out\r"
expect "sftp>"
send "mput s1.txt s2.txt s3.lst\r"
expect "sftp>"
send "bye\r"
expect eof

but in the abpve code it transfers only the last file i.e s3.lst

then its more like sftp client issue..try manually and see if mput command works