shell script for ftp files passed in command line argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script for ftp files passed in command line argument
# 1  
Old 03-22-2011
Network shell script for ftp files passed in command line argument

i want to write a shell script function that will ftp the files passed in the command line . i have written a shell script for ftp but how will it do for all files passed in command line argument ,

i am passing 4 files as argument

Code:
./ftp.sh  file1 file2 file3 file4

code written by me :---


Code:
if [ $# -eq 0 ]
        then
                echo "Enter the files to be ftp as Arugment:- "
                exit 1
        fi
echo " "
echo "$@"


hostname="someip"
username="root"
password="root"

ftpbuild(){
sftp  $hostname <<EOF
cd /tmp
mput $1  or $* ( getting error for both )
quit
EOF
}

ftpbuild - calling the function here .

getting error and not getting ftped .


do i need to declare any array here for i will use for loop for this . but if i will use for loop then for 5 files it will call the function 5 five as ftp connection ,.,


Help me out here

Last edited by pludi; 03-22-2011 at 08:42 AM..
# 2  
Old 03-22-2011
Code:
man sftp

look at the -b option
# 3  
Old 03-22-2011
but how will it help me reading from command line argument .
# 4  
Old 03-22-2011

The ftp command is not intended to be used in scripts.

Use the ncftp family of commands instead.

Better still, use scp if you can.
# 5  
Old 03-22-2011
Also your problem with $1 is that within the function ftpbuild you can only access the parameters passed to that function when it was called not those passed to the whole script. call ftpbuild like this to pass the main script parameters on to the function:

Code:
ftpbuild $@

# 6  
Old 03-23-2011
Build .netrc file in your script and then call ftp.
google .netrc for samples.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting number of argument passed to a shell script

Hi Experts, I have been trying to work on a simple shell script that will just add the two argument passed to it. Here is what i tried : #!/bin/bash welcome(){ echo "Welcome to this Progg. which will accept two parameter" } main_logic(){ arg=$# echo "Number of argument passed is... (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. How to Post in the The UNIX and Linux Forums

Read a json file passed as cmd line argument

usage: myscript.sh config.json config.json: { "HOST":"abc", "DB_NM":"xyz", "USR_NM":"asd", "PWD":"xxx", ......... ......... ......... ........ } myscript.sh: (2 Replies)
Discussion started by: RGRT
2 Replies

3. UNIX for Dummies Questions & Answers

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies

4. Shell Programming and Scripting

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies

5. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

6. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

7. Shell Programming and Scripting

Passing value as a command line argument in awk script.

I have one working awk command line. Which taking data from the “J1202523.TXT” file and generating the “brazil.dat” file. PFB code. awk '{ DUNS = substr($0,0,9);if ( substr($0,14,3) == "089" ) print DUNS }' J1202523.TXT > Brazil.dat But now I want to pass two parameter as a command line argument... (4 Replies)
Discussion started by: humaemo
4 Replies

8. UNIX for Dummies Questions & Answers

Passing command output as an argument to a shell script

Hi, I have a very small requirement where i need to pass command output as an argument while invoking the shell script.. I need to call like this sh testscript.sh ' ls -t Appl*and*abc* | head -n 1' This will list one file name as ana argument.. I will be using "$1" in the shell... (2 Replies)
Discussion started by: pssandeep
2 Replies

9. UNIX for Dummies Questions & Answers

Passing command line argument between shell's

Hi, I am facing a problem to pass command line arguments that looks like <script name> aa bb "cc" dd "ee" I want to pass all 5 elements include the " (brackets). when I print the @ARGV the " disappear. I hope I explain myself Regards, Ziv (4 Replies)
Discussion started by: zivsegal
4 Replies

10. UNIX for Dummies Questions & Answers

pipe output to script as command line argument

i want to redirect output of one command as the command line argument of another script for example, say i would run this command: find . -xdev -type f -size +4096 -exec ls -al {} \; i wan to be able to do something like: echo +4096 | find . -xdev -type f -size ****** -exec... (3 Replies)
Discussion started by: IMTheNachoMan
3 Replies
Login or Register to Ask a Question