FTP File to Multiple Host


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP File to Multiple Host
# 1  
Old 08-01-2015
FTP File to Multiple Host

I need to ftp a file to several servers. I have seen a lot examples on how to ftp several files from a host, none for what I need. I'm sorry if this has already been answered, hopefully someone can point me in the right direction. I'm very new to scripting.

Thanks.
# 2  
Old 08-01-2015
best is to do it with a loop:

Code:
#!/bin/sh
for host in `cat file-of-hostnames`; do
  echo "use <userid> <password>
put filename
" | ftp -n $host
done

This presumes a common userid/password on all target hosts. Otherwise you could add that information to the lines in the file-of-hostnames, and parse them out inside the loop. Or use a perl script for a similar purpose.

Oh, don't EVER listen to anyone proposing "anonymous ftp". That's like Pippin looking into the Palantir.
# 3  
Old 08-03-2015
Thanks that worked. I tried to expand on it so it will create a log of completed & failed transfers, but my if then statement is not working. The else statement works. I don't know what master error mean. What am I doing wrong? Also I would like to record the host ip address in the log files.

Code:
#!/bin/bash
USER=admin
PASSWD=admin
for host in `cat hosts-list.txt`
do
ftp -n -v $host <<EOF >ftp.log
ascii
user $USER $PASSWD
prompt
cd switch
put pre_banner.txt
bye
EOF

	 numbers=`grep 226 ftp.log`

                if [ "$numbers" = "226" ];
                then

                        echo $line complete. >> complete.ftp.log

                else

                        echo $line failed. >> fail.ftp.log

                        Master_Error=1

                fi
done

---------- Post updated at 09:31 PM ---------- Previous update was at 07:32 PM ----------

I got a working model, but might not be the best way. are there any improvements anyone recommend?

Code:
#!/bin/bash
USER=user
PASSWD=password
for host in `cat hosts-list.txt`
do
ftp -n -v $host <<EOF >ftp.log
ascii
user $USER $PASSWD
prompt
cd switch
put pre_banner.txt
bye
EOF

complete=$(grep -c 226 ftp.log)
system=$(grep -i connected ftp.log)

                if [ $complete = 1 ];
		then
			echo $system >> complete.ftp.log

                else
                    echo $system >> fail.ftp.log
		fi
done


Last edited by slqtech; 08-04-2015 at 07:07 PM..
# 4  
Old 08-04-2015
even though
Code:
 #from man sh
       string1 == string2
       string1 = string2
              True if the strings are equal.  = should be used with the  test
              command for POSIX conformance.

Your script has
Code:
if [ "$numbers" = "226" ];
then

and
Code:
[ $complete = 1 ]

in the context you're using it, the "string equivalence" operator is the double-equal ==

This problem is in several places...

You may also wish to explore the significant difference between '==' and '-eq' which is the aritmetical equivalence operator.

Last edited by featheredfrog; 08-04-2015 at 09:53 AM.. Reason: edited because I can't keep my mouth shut. EVERYTHING becomes a tutorial.
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 run a shell script on a remote host using ftp

Hi, is there a way I can run a shell script through ftp on a remote host? The remote host doesn't have ssh running so I can't use ssh. (7 Replies)
Discussion started by: mrskittles99
7 Replies

2. Shell Programming and Scripting

How to ftp multiple files by taking the file name from a input file.

Hi, I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt. vi input.txt abc.c welcome.c new.c welcome1.c for ftp'ing a single file say 'new.c' the following code... (2 Replies)
Discussion started by: i.srini89
2 Replies

3. Shell Programming and Scripting

Login to multiple host without using Expect

Hello , I have a problem which involves a set of command should be executed on remote host and output should be stored in a file. But due to security reason I can not use expect to enter the password and its not possible to create password less login for multiple user to do the same thing and we... (10 Replies)
Discussion started by: pratapsingh
10 Replies

4. UNIX for Dummies Questions & Answers

how to handle multiple apps on host?

So, I'm going to install Oracle DB within my Suse host... Also, I would like to run Virtual Box and Tomcat.. ok, tomcat is going to be runnable app that will start at boot.. but, how to handle Oracle and virtual box? I would like to have an Oracle under it's own user, and to be able to use... (0 Replies)
Discussion started by: bongo
0 Replies

5. Shell Programming and Scripting

rsh to many hosts the ftp output to single host

Hi guys. i need some help, i need to create a script in tcsh that rsh into all my hosts that we have at our business, then cd to a directory (cd /apps/users) then grab a file from the users folder and ftp it back to my windows machine. can someone please help? Kind regards. Brian Behrens (2 Replies)
Discussion started by: brian112
2 Replies

6. Shell Programming and Scripting

change password for multiple host

1-How can i change root password of 5 Fedora 11 machines (server1 server2 server3 server4 server5) with a single script , for example make password : 123456 NB. from server1 i can via ssh connect to the others machines without a password Please help. (3 Replies)
Discussion started by: chang-lee
3 Replies

7. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

8. UNIX for Dummies Questions & Answers

Get IP of FTP Host

All, This may be very trivial, but I am unaware. We normally do FTP to hosts with their hostname as follows. $ ftp c.b.a.com Now, How do I know the IP address of c.b.a.com? Thanks, Rahul. (3 Replies)
Discussion started by: rahulrathod
3 Replies

9. IP Networking

FTP - Connection Closed By Remote Host

Hi, I am having a problem with our AIX 4.3.3 Server accessing FTP. The error is " Connection Closed By Remote Host". Scenario: Since i put a default gateway on the server FTP connection is having a problem but when i remove the default gateway it will works fine.. Is there any way not... (1 Reply)
Discussion started by: mouglybean
1 Replies

10. UNIX for Advanced & Expert Users

How do I ftp to an unknown host?

after ftp. ftp.umass.edu, I get "UNKNOWN HOST" There is no prompt for username. What do I do so that I can ftp files out? Or even email, to an unknown host. (3 Replies)
Discussion started by: AllyJones
3 Replies
Login or Register to Ask a Question