Re: [ILUG] ftp script

From: Kevin O' Riordan (kor at domain compsoc.com)
Date: Thu 26 Sep 2002 - 09:18:02 IST


Hi Kae,

you could use shell 'here documents'. Not as sophisticated as perl or
expect, but can probably be made to do the job. The code below is
untested, crude, may contain artificial preservatives, blah.

-kev

    #!/bin/bash

    conf_file="${HOME}/.blahconf"
    r_host=$(grep '^host=' "conf_file" | sed -e 's/^\(host=\)\(.*\)$/\2/g')
    r_host=$(grep '^user=' "conf_file" | sed -e 's/^\(user=\)\(.*\)$/\2/g')
    r_pass=$(grep '^pass=' "conf_file" | sed -e 's/^\(pass=\)\(.*\)$/\2/g')

    l_tmpfile=$(mktemp, mkdir in /tmp, whatever)
    l_files=""

    # See what's on the remote host.
    ftp -in <<-EOT
        open $r_host
        user $r_user $r_pass
        ls -l $l_tmpfile
        bye
    EOT

    # Build list of files we want from remote host.
    r_files_wanted=$(grep blah "$r_files_wanted | awk '{print $9}')

    # Get files.
    ftp -in <<-EOT
        open $r_host
        user $r_user $r_pass
        $(
            for f in $r_files_wanted; do
                echo "get $f"
            done
        )
        bye
    EOT

>
> the script should retain usernames, passwords, hosts, directories etc in
> a conf file
>
> an example of how to FTP in perl (without the CPAN module, if possible)
> would be good if the above is not available.
>
> --
> Kae Verens _______\_ webworks.ie
> work: www.webworks.ie _____\\__ webhosts
> play: www.contactjuggling.org ___\\\___ design
> kae: kverens.contactjuggling.org _\\\\____ code
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie

-- 
On Pungenday, the 49th day of Bureaucracy, Kae Verens testified:
> has anyone got a simple perl ftp script (upload/download)?
> 
> the script should retain usernames, passwords, hosts, directories etc in 
> a conf file
> 
> an example of how to FTP in perl (without the CPAN module, if possible) 
> would be good if the above is not available.
> 
> -- 
> Kae Verens               _______\_   webworks.ie
> work: www.webworks.ie       _____\\__   webhosts
> play: www.contactjuggling.org  ___\\\___  design
> kae:  kverens.contactjuggling.org _\\\\____ code
> 
> -- 
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie
-- 
	"The majority of the stupid is invincible and guaranteed
	 for all time.  The terror of their tyranny, however, is
	 alleviated by their lack of consistency."
               - Albert Einstein


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:19:05 GMT