Help with FTPing in script

Help with FTPing in script

Post by William Ya » Wed, 18 Oct 1995 04:00:00





>            I am new to Unix programming and I need help in writing
> a shell script to FTP to another site. I am having trouble entering the
> login name and the password from the script.  I have tried just hard
> coding the name and password in the script but I can not get a line feed
> or carriage return after them so I do not know if it is even waiting for
> one.  I am trying to avoid using the automatic login of TCP/IP and would
> rather have it done in a script with the login name and password either
> hard coded or passed as a command line argument to start the session.
> Any help would be greatly appreciated. Thanks alot.

#! /bin/sh
#
# should work on BSDish UNIXes, can be made to work on SVR4ish UNIXes with
# a tiny bit of tuning.
#
# this code ain't supported.
#

FTPHOST=wuarchive.wustl.edu             # FTP server    

FILENAME=coolstuf.zip                   # name of file to get

FTPUSER=anonymous                       # FTP username
FTPPASS=                                # FTP password

echo "getting ${FTPHOST}:${GETFILEPATH}/${FILENAME} ..."

echo "quote user ${FTPUSER}
quote pass ${FTPPASS}
bin
prompt
cd ${GETFILEPATH}
get ${FILENAME}
" | ftp -n ${FTPHOST} 2>&1 >> /dev/null

echo "gotten."

 
 
 

Help with FTPing in script

Post by John R. Har » Wed, 18 Oct 1995 04:00:00



>            I am new to Unix programming and I need help in writing
>a shell script to FTP to another site. I am having trouble entering the
>login name and the password from the script.  I have tried just hard
>coding the name and password in the script but I can not get a line feed
>or carriage return after them so I do not know if it is even waiting for
>one.  I am trying to avoid using the automatic login of TCP/IP and would
>rather have it done in a script with the login name and password either
>hard coded or passed as a command line argument to start the session.
>Any help would be greatly appreciated. Thanks alot.

Sounds like you want "expect" by Don Libes (ftp.cme.nist.gov//pub/expect)
I think he even has an example that does this.

 
 
 

Help with FTPing in script

Post by Wendell G » Wed, 18 Oct 1995 04:00:00


an infinite number of monkeys calling themselves Ezekiel Majek

RB>          I am new to Unix programming and I need help in writing
RB>a shell script to FTP to another site. I am having trouble entering the
RB>login name and the password from the script.  I have tried just hard
RB>coding the name and password in the script but I can not get a line feed
RB>or carriage return after them so I do not know if it is even waiting for
RB>one.  I am trying to avoid using the automatic login of TCP/IP and would
RB>rather have it done in a script with the login name and password either
RB>hard coded or passed as a command line argument to start the session.
RB>Any help would be greatly appreciated. Thanks alot.
RB>                  Zeke

The following script will do what you want, but will exit from ftp after
the line "EOF" is read.  $1 contains the site name, $2 the user name to
use and $3 the password.  Since command line arguments are visible to
ps while the script is running, I would refrain from using this for anything
but anonymous ftp.

#!/bin/sh
ftp -n $1 << EOF
user $2 $3
ls
EOF

You can fully automate an ftp session with this by replacing the ls with
other commands, but there are generally much better ways to do batch ftp.

--r

--------------------------------------------------------------------------
| "The density of the information         | Rick Bradley                 |
|  presented is near the theoretical      | Starving Graduate Student    |
|  minimum." --FreeBSD manual:  comsat(8) | CS Dept. -- SUNY Stony Brook |
--------------------------------------------------------------------------

 
 
 

1. Scripting FTP tasks - How to use FTP in bash scripts

After a long fight with bash scripts, not convinced that I can't do it
in Unix! I managed to write the following small script that automates
FTP tasks ( I use it to backup my boxes ).
Enjoy !

-------------------------------------------------------
#!/usr/local/bin/bash
# This script automates FTP access for backup purposes.
# Change the server IP/Hostname, user name, password and command list
to perform more tasks on other servers.
# Have a nice day!

hostname="10.10.10.2"
username="UNAME"
password="PASSWORD"
ftp -n $hostname  <<EOF
quote USER $username                
quote PASS $password              
bin                                
hash                                

<<< Command list goes here >>>

quit                              
EOF

-------------------------------------------------------

-ashraf

2. internet connection troubles.

3. Need HELP to Log User Log-ins form the internet

4. HELP: Does Linux read ACER PCI?

5. Netscape helpers and plug-ins, also java help

6. Stop A on PS2 keyboard

7. Encrypting ftp password in ftp batch script???

8. Linux Unleashed: Problems running off CDROM

9. HELP WITH DIAL INS

10. script to FTP a file from a FTP site on a regular basis

11. Need Help on setting up getty for dial-ins

12. New HOWTO....HOWTO-Hose-RedHat-Installation (help!)

13. "dir" format of FTP servers (was: FTP Expect script)