Need help in Unix

mrmagoo_83

2[H]4U
Joined
Aug 8, 2002
Messages
3,068
I am trying to write a script for my unix setup at work. The basis is I must FTP to a secure server download a certain set of files from certain directories, then exit.

My problem is that I can get it to FTP and connect, but it will not return the username or password. Once I manually type them in it then spits them up on the screen. Now I am very new to Unix scripting so don't be too harsh on me :)

Here is what I have so far:

Code:
#!/bin/sh
/sbin/route delete default
/sbin/ifconfig zrl0:0 down
/sbin/ifconfig zrl0 down
/sbin/ifconfig znb2 192.168.1.172 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add default gw 192.168.1.1

ftp -n 192.168.1.201
user XXX XXX
bin
cd loads/
get XXX.txt
bye


Can anyone help me fix this where it actually logs into the FTP server for me?
 
For starters, FTP is not a 'secure' protocol... it transmits everything over plaintext. You might also consider fixing your routing after the script is run (or have it set up properly to begin with).

FTP isn't the most scriptable of programs, being an interactive one. I'd probably just use
Code:
wget [url]ftp://user:password@ftpserver/XXX.txt/[/url]

(assuming wget understands FTP passwords in the URL - I don't have any FTP servers to check it on).


Otherwise, you're stuck doing something like
Code:
echo "command
command
command
command" | ftp
which isn't so bad, but being able to use wget would be far more elegant.
 
I don't know what version of unix you are using but checking FreeBSD man pages for ftp I see this:

Code:
FTP(1)                  FreeBSD General Commands Manual                 FTP(1)

NAME
     ftp, pftp, gate-ftp -- ARPANET file transfer program

SYNOPSIS
     ftp [-46adeginptUvV] [-P port] [-s src_addr] [host [port]]
     ftp [url]ftp://[user:password@]host[/url][:port]/file[/]
     ftp [url]http://host[/url][:port]/file
     ftp host:[/path/]file[/]

It would appear that you could possibly define the username, password and file to be pulled all from the command line.

I haven't tried it myself so YMMV.
 
Back
Top