Loops within ftp shell session


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loops within ftp shell session
# 1  
Old 01-18-2006
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 [ $x -lt $filenum ]
do
cd pacsftp01
put test.txt
delete test.txt
x=`expr $x + 1`
done
quit
echo $x files transferred
SCRIPT
--------------------------------------------------------------------
questions:
How can i execute a while loop within the ftp sessions?
What does "<<SCRIPT" do?

Thnks,
Zaff
# 2  
Old 01-18-2006
zaff,
You are trying to loop inside the ftp command (everything that you are doing after the << is inside the ftp command) That is not going to work, as ftp does not support these commands.

A better suggestion is to construct a ftp script and feed it to the ftp program.
Code:
#!/bin/sh
USER=myuser
PASSWD=mypass
filenum=$1
x=0

echo "open 159.167.95.199
user $USER $PASSWD
binary
cd pacsftp01" > /tmp/ftp.$$
while [ $x -lt $filenum ]
do
echo "put test.txt
delete test.txt" >> tmp/ftp.$$
x=`expr $x + 1`
done
echo "quit" >> /tmp/ftp.$$
ftp -ivn < /tmp/ftp.$$
echo $x files transferred
rm /tmp/ftp.$$


Last edited by blowtorch; 01-18-2006 at 11:28 AM.. Reason: remove --not tested-- as it just was
# 3  
Old 01-18-2006
thanks for that Blowtorch!
# 4  
Old 01-18-2006
Quote:
Originally Posted by blowtorch
zaff,
You are trying to loop inside the ftp command (everything that you are doing after the << is inside the ftp command) That is not going to work, as ftp does not support these commands.

A better suggestion is to construct a ftp script and feed it to the ftp program.
Code:
#!/bin/sh
USER=myuser
PASSWD=mypass
filenum=$1
x=0

echo "open 159.167.95.199
user $USER $PASSWD
binary
cd pacsftp01" > /tmp/ftp.$$
while [ $x -lt $filenum ]
do
echo "put test.txt
delete test.txt" >> tmp/ftp.$$
x=`expr $x + 1`
done
echo "quit" >> /tmp/ftp.$$
ftp -ivn < /tmp/ftp.$$
echo $x files transferred
rm /tmp/ftp.$$


My only comment is that the entire time you are transferring the ftp files, your USER and PASS are world-readable in /tmp/ftp.$$
# 5  
Old 01-18-2006
My only comment is that lots of folks seem to be ignoring the faq section. *sigh* But, oh well, at least some people read them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

2. Shell Programming and Scripting

Using pipe in FTP session

Hi All , I want to use pipe in ftp session . Please let me know if there is any possibility I have done FTP to a remote host with proper username and password Now I want to take the latest file in a directory . The below is not workinf ftp> ls -lrt |... (4 Replies)
Discussion started by: Sandeep Lade
4 Replies

3. Shell Programming and Scripting

running a script in a ftp session

Hi guys, I am using a script that run ftp and transfer file from my source server to the destination server. Since i have transferred my files to the destination server, now i want to run a script at the destination server. Could you please help me regarding how to run a script in a ftp... (7 Replies)
Discussion started by: jaituteja
7 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. Shell Programming and Scripting

How to get latest file via FTP session

Hello , My requirement is as follows: I want to connect to a remote FTP server using FTP and then get the latest file from server location can u pls share code snippet for this ? Regards, Suresh (4 Replies)
Discussion started by: sureshg_sampat
4 Replies

6. UNIX for Dummies Questions & Answers

FTP Session

In FTP session, how could know the present working directory in local machine? pwd command gives the present working directory for remote machine only. (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

7. Shell Programming and Scripting

Running a script for every ftp session

Hello all, I have written a shell script which would prompt the user to enter some name and a folder would be created by that name. This script should run automatically when the users provide there credentials during a FTP session and for every FTP session. And after they have provided there... (5 Replies)
Discussion started by: h3llh0l3
5 Replies

8. Shell Programming and Scripting

Looping in FTP session

Hi I am trying rename multiple files in a remote location by connecting through FTP. How do i do this? I get error as for is not FTP command. I looked the FAQ for scripting but it is doesnt relate to my post. Please help. Thanks ftp -in >Error.log <<! open $HOST user $User $Pwd for... (2 Replies)
Discussion started by: appsguy616
2 Replies

9. Shell Programming and Scripting

display while in ftp session

Is there any command which displays date while i am in a ftp session? I tried the date command, but in vain ftp> date ?Invalid command ftp> Can someone please help me. Thanks (2 Replies)
Discussion started by: vivek_damodaran
2 Replies

10. UNIX for Advanced & Expert Users

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... (6 Replies)
Discussion started by: jsalz638
6 Replies
Login or Register to Ask a Question