For Loops Within Ftp Comands


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users For Loops Within Ftp Comands
# 1  
Old 07-01-2004
Question For Loops Within Ftp Comands

I am having trouble getting files to ftp over when I run the file names through a loop. If I just do one file it works, but inside of a for loop it does not.

Help!

################section 2

cd /home/salazar/chk_data
chmod 777 *
ftp -n 161.241.--.-- <<!
user anonymous \n
ascii

for job2 in 3t 11 12 13 14 18 19 25 26 30 37 205 210 215 218 220 225 230 255 260 262 305 310 311 315 320 325 330 331 335 336 337 341 343 345 360 375 380 381

read x

do
CFNAME="$job2".chk
RFNAME="$job2".rem

cd ../$job2
put /home/salazar/chk_data/$CFNAME $CFNAME
put /home/salazar/chk_data/$RFNAME $RFNAME

done

read x

bye
!
# 2  
Old 07-01-2004
Please navigate
Our Home Page -> Answers to Frequently Asked Questions -> Automate FTP / Scripting FTP Transfers
# 3  
Old 07-02-2004
I couldn't find what I needed there. Any other suggestions?
# 4  
Old 07-02-2004
It's a very small step from this....
Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz
print -p bye

wait
exit 0

to this....
Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p binary
for job2 in 3t 11 12 13   ; do 
      print -p cd  $job2
      CFNAME="$job2".chk
      print -p  put /home/salazar/chk_data/$CFNAME $CFNAME
done
print -p bye
wait
exit 0

That's one of the advantages that the coprocess technique has over the here-document technique.

Last edited by Perderabo; 07-28-2005 at 12:15 PM..
# 5  
Old 10-06-2006
For loop in SFTP

Could you please suggest or give a sample script to use for loops in SFTP script?
The SFTP should be in non-interactive mode.

Thanks & Regards,
Vijay
# 6  
Old 10-18-2007
Power Recieving while forking background process

Quote:
Originally Posted by Perderabo
It's a very small step from this....
Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz
print -p bye

wait
exit 0

to this....
Code:
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p binary
for job2 in 3t 11 12 13   ; do 
      print -p cd  $job2
      CFNAME="$job2".chk
      print -p  put /home/salazar/chk_data/$CFNAME $CFNAME
done
print -p bye
wait
exit 0

That's one of the advantages that the coprocess technique has over the here-document technique.

Hi Perderabo,

i am recieving the following error message while executing the above snippet of code.

could you advice what should i do to avoid the below error


test3: line 25: syntax error near unexpected token `&'
test3: line 25: `ftp -nv >&4 2>&4 | &'
# 7  
Old 10-22-2007
Quote:
Originally Posted by harim
Hi Perderabo,

i am recieving the following error message while executing the above snippet of code.

could you advice what should i do to avoid the below error


test3: line 25: syntax error near unexpected token `&'
test3: line 25: `ftp -nv >&4 2>&4 | &'

Cut and paste if you can't get the syntax right. There is no space between the | and the & in my code. You added a space between them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use of the below ftp comands

plz let me know what the below ftp is doing it . ftp -m amazon-d . -i /test/load/y748_W*.stc (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. UNIX for Dummies Questions & Answers

Execute multiple comands on one single line

hi, I have a litle problem i wish to excute this comand : ./test.sh -e txt /home -l a so what it says is that "-e" shows me all the extenions that are ".txt" in "home" this works but then i wish that "-l" will show all files begining in this case with the letter "a" . Both comands work... (5 Replies)
Discussion started by: samirboss
5 Replies

3. Shell Programming and Scripting

Script Help - Multi Comands

Hi guys I am trying to get a bunch of lines into a .sh script that will let me easily run a bunch of commands on its own without me having to be there... I have done this with other things but apparetnly it doesn't like to use yum.. I will post my script you will see what im trying to do.. ... (3 Replies)
Discussion started by: Bigstack
3 Replies

4. Shell Programming and Scripting

Korn Shell programming (FTP, LOOPS, GREP)

Hello All, I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database. To this, I have to construct a loop that checks a specified folder for a file. If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Discussion started by: jonesdk5
2 Replies

5. Solaris

Solaris 10 network, process, database related comands

Hi everbody, Can anyone let me know the resources for list of network, process, database related commands of solaris10 possibly with little bit of explanation. Thanks in advance, Chandra Sekhar. (1 Reply)
Discussion started by: chandoo.java
1 Replies

6. Cybersecurity

comands inside the script

hi, i want to put a set of commands inside a script and executing commands sequentially. there are 2 commands, the first command copies the program from my machine to another machine, execute it and get the result on my machine. the second command removes the program which was copied to the... (4 Replies)
Discussion started by: mercuryshipzz
4 Replies

7. Shell Programming and Scripting

Loops within ftp shell session

Hi guys, i need to script the sending of multiple files through one ftp session. I have done this so far: ---------------------------------------------------------------- #!/bin/sh USER=myuser PASSWD=mypass filenum=$1 x=0 ftp -n 159.167.95.199 <<SCRIPT user $USER $PASSWD binary while ... (4 Replies)
Discussion started by: zaff
4 Replies

8. Shell Programming and Scripting

how to identify the type of shell using comands..

Dear friends, please tell me how to identify the type of the shell (whether cShell, kshell or anything else) please tell me the command. waiting for ur reply.... regards, swamymns (2 Replies)
Discussion started by: swamymns
2 Replies

9. Shell Programming and Scripting

loops in loops

ok, i tried to write a script called purge.sh which searches current process' for a specified user running a process with a specified keyword. it also prompts the user to see how many times to purge for the specified process and how many different processes they wish to do this to.it worked until... (11 Replies)
Discussion started by: Blip
11 Replies

10. Programming

External comands in C?

Hey all, I'm writting my first C program (Apart from the little ones I did to learn the program). What I want for this program to do is ping a range of IP's and then place the reply if alive into a file the compare all in that file to the /etc/hosts file to find the host name. I know I... (2 Replies)
Discussion started by: merlin
2 Replies
Login or Register to Ask a Question