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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass an array containing file names to a sftp script?
# 1  
Old 08-07-2013
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
Code:
FILE_NAMES="s1.txt s2.txt s3.lst"
/home/sftp_script $FILE_NAMES

sftp_script
Code:
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.
# 2  
Old 08-07-2013
make your $FILE_NAMES within quotes

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

# 3  
Old 08-07-2013
i donot think i will work i tried hardcoding the filenames inside sftp script
Code:
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
# 4  
Old 08-07-2013
then its more like sftp client issue..try manually and see if mput command works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Need script to pass all sql file names in a directory to DB query

Hi All, In this path /home/all_files we have follwing files and direcotries proc_edf_sot.sql proc_ssc_sot.sql func_dfg_sot.sql sot unic cmr sdc under sot directory we have other directories sql pas ref under sql directory we have sql_sot sql_mat (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

3. Shell Programming and Scripting

File names as array element in ksh

Hi, I have an ksh array(ARR). the elements to the array are file names. i need to go to each file in the array and manipulate the records. for name in ${files}; do ---this loop is for all the file names in the array for i in $(wc -l < $name); do --this loop is for all the records in... (20 Replies)
Discussion started by: usrrenny
20 Replies

4. Shell Programming and Scripting

How to pass arguments to an sftp script??

hi, Is it possible to pass arguments to a sftp script and use those arguments in the program? for example sftp_script FILENAME=$1 #!/usr/bin/expect spawn /usr/bin/sftp abc@ftp.abc.com expect "abc@ftp.abc.com's password:" send "pass\r" expect "sftp>" send "mput $FILENAME\r"... (9 Replies)
Discussion started by: Little
9 Replies

5. Shell Programming and Scripting

How to pass an array to a function in shell script.?

hi, I have a array say SAP_ARRAY="s1.txt" SAP_ARRAY="s2.txt" how can i pass this full array to a function. here is the sample code i am using.. CHECK_NO_FILES() { FARRAY=$1 echo "FARRAY = $FARRAY" echo "FARRAY = $FARRAY" ............... (5 Replies)
Discussion started by: Little
5 Replies

6. Shell Programming and Scripting

Creating array containing file names

I am wondering how I can save the file names (stored in $file or $fnames) in array which I can access with an index. alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`' set narg = $#argv while ($iarg < $narg) MATH iarg = $iarg + 1 set arg = $argv set opt = ` echo $arg | awk... (1 Reply)
Discussion started by: kristinu
1 Replies

7. Shell Programming and Scripting

Can we pass an array of strings from a Perl Program to a Shell Script?

Hi Folks, The subject is my question: Can we pass an array of strings from a Perl Program to a Shell Script? Please provide some sample code. Thanks ---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ---------- I got it. Its here:... (0 Replies)
Discussion started by: som.nitk
0 Replies

8. Shell Programming and Scripting

How to pass an array as arg to a script..

Hi, Please guide to pass an array as a arg to a script... for example, I have a script small.sh to find the small no of given arg as below... #! /bin/sh # this script is for finding the small number set -A arr_no_updates small=$1 i=1 for arr in $@ do if (3 Replies)
Discussion started by: little_wonder
3 Replies

9. Programming

How to pass C array as input to Shell script

Hi, In the below C code , i want to pass the array to a unix shel script. my script should called as ex myscript 1,2,3 #include <stdio.h> int main() { int a={1,2,3}; } Thanks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. UNIX for Dummies Questions & Answers

How to Pass a list of file names to ls

Hi I have a list of file names generated from a find command. The list does not show complete file information. I would like to do this: generate the list of file names pass each file name generated to ls -l command what is the best way to do this without a script? I have tried... (2 Replies)
Discussion started by: GMMike
2 Replies
Login or Register to Ask a Question