Tech Support > Operating Systems > Linux / Variants > FTP bash script wanted
FTP bash script wanted
Posted by Adams-Blake Company on January 12th, 2004


re: Slackware 9.1, KDE 3.14

I'm looking for a script that will login to my remote (dedicated) server
(running Linux of some flavor) from my home machine and download a file and
then log off and cut the connection.

I want to run this each night via cron.

Anyone have such a beast?

Thanks,

Al

Posted by William Park on January 12th, 2004


Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> wrote:
Sure. Any money involved?

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing.

Posted by Tony Curtis on January 12th, 2004


wget

hth
t

Posted by Alan Connor on January 12th, 2004


On Sun, 11 Jan 2004 19:04:04 -0800, Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> wrote:
ncftpget is made for just this purpose.

Highly recommended. Comes with the ncftp client package.

a
ncftpget(1) ncftpget(1)



NAME
ncftpget - Internet file transfer program for scripts

SYNOPSIS
ncftpget [options] remote-host local-directory remote-
files...

ncftpget -f login.cfg [options] local-directory remote-
files...

ncftpget [options] ftp://url.style.host/path/name

ncftpget -c [options] remote-host remote-file > stdout

ncftpget -c [options] ftp://url.style.host/path/name >
stdout


Basically you just write out the commandline in a file, make it executable
with #!/bin/sh at the top, put it in your PATH and write a crontab calling
the script.

Otherwise, it really isn't hard to write a script for an ftp client that
you know.

comp.unix.shell


AC


Posted by Chris F.A. Johnson on January 12th, 2004


On Mon, 12 Jan 2004 at 03:04 GMT, Adams-Blake Company wrote:
Put this (with appropriate changes) in your $HOME/.netrc file:

----- cut here -----
machine remote.server
login your.login.name
password your.passwd
macdef init
binary
get file.name

----- cut here (include blank line in file) -----

Change the permissions on .netrc:

chmod 600 $HOME/.netrc

In your crontab file, use the command "ftp remote.server".


--
Chris F.A. Johnson http://cfaj.freeshell.org
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Posted by Michael Black on January 12th, 2004


Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> wrote in message news:<10043vbm295cva1@news20.forteinc.com>...
This is an easy one since I've been doing it this week.

I was using wget, because I was sucking up whole directories.

I just put it in a script, along with the command to drop the
connection. Basically just put in the script what you'd be
using to do the download and disconnect manually. I started
it by hand, but it turned off when finished. I used an "at"
command to drop the connection at a fixed time, in case the
download was not finished by a time I thought the phone
should be free.

In your case, you'd just have cron running the script
at a given time.

Michael

Posted by Adams-Blake Company on January 12th, 2004


Michael Black wrote:


Thanks for all the help guys. I ended up using wget. I found that there is an
ftp user/password construct and it works fine. Is it less secure than scp or
fpt or whatever? I'm downloading a mysql dump file.

Thanks,
Al


Posted by Jim Richardson on January 12th, 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 12 Jan 2004 00:06:34 -0800,
Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> wrote:

It is ftp, with all the limits and security issues that brings. So be
aware of that.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAAnmsd90bcYOAWPYRAie/AJ4899cWxlntar90DN3ll6AgcnVz3gCgrTZL
kaR3daGZrsdWevt0aOl+HcY=
=i1t9
-----END PGP SIGNATURE-----

--
Jim Richardson http://www.eskimo.com/~warlock
Only wimps use tape backup: _real_ men just upload their important stuff
on ftp, and let the rest of the world mirror it.
-- Linus Torvalds

Posted by Molchun on January 12th, 2004


Adams-Blake Company wrote:

I had to do exactly the same task - downloading files through cron twice a
day but in addition I have to mail the downloaded files to my boss and then
stash them someware for further ref. I found that lftp was the best for the
job. Below are the scripts I cooked up for this so you or someone else
might find it useful.

My scripting skills are far from brilliant but my boss doesn't know about it
and it does the job .

This to be run by cron from $HOMEDIR:

----- cut -----
#!/bin/bash

# This script to be put in $HOMEDIR

HOMEDIR=/home/e2c

function send_files {

for FILE in *; do

if [ -e "$FILE" ]; then

echo "The new files are retrieved at `date` and attached. Enjoy!" | nail\
-s "Automated FTP checking" -a "$FILE" user@domain.co.uk >> ../log 2>&1

if [ $? -eq 0 ]; then
continue
else
echo "Nail returned bad exit code while sending attachments!" >> ../log
exit 1
fi

else

echo "Some files tested nonexistent in function send_files!" >> ../log
exit 1

fi

done

return 0

}

cd $HOMEDIR/cur
if [ $? -ne 0 ]; then
exit 1
fi

echo "" >> ../log
echo "`date`" >> ../log
lftp -f ../lftp.run >> ../log 2>&1

ls | grep pattern &> /dev/null
EXITCODE=$?

if [ "$EXITCODE" -eq 1 ]; then

echo "There are no files to retrieve at `date`" | nail -s "Automated FTP \
checking" user@domain.co.uk

if [ $? -ne 0 ]; then
echo "Nail returned bad exit code while sending info!" >> ../log
exit 1
else
echo "Info has been sent!" >> ../log
exit 0
fi

else

send_files

if [ $? -eq 0 ];then

echo "Files have been sent!" >> ../log
mv pattern* ../arc

if [ $? -eq 0 ];then
echo "Files have been moved to archive!" >> ../log
exit 0
else
echo "There was an error moving files!" >> ../log
exit 1
fi

else

echo "Shouldn't get here "

fi

fi
---- cut ----

And this is for lftp itself
This file to be put in $HOMEDFIR as well, the above script will look for it
there.

---- cut ----
open -u username,passwd ftp.ftpsite.com
cd outbound
mget -E pattern*
close
quit
---- cut ----

That's it both files to be put in $HOMEDIR and the first one to be run by
cron at whatever intervals. In the $HOMEDIR you also need two directories
"cur" and "arc" since they are both referenced from the script.

--
Jabber: molchun@jabber.org
PGP ID: 0x304563A8


Posted by joe@invalid.address on January 12th, 2004


Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> writes:

On many systems your username and password will be visible in a ps
listing while wget is running. These also get sent in plain text
across the wire.

If you can use scp or sftp they would certainly be more secure,
especially if you setup an agent to manage the login (no passwords in
files that way).

Joe

Posted by John Winters on January 12th, 2004


In article <1004lbijvv16o30@news20.forteinc.com>,
Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> wrote:
[snip]
Definitely a lot less secure than using scp. Ftp sends your user id and
password over the net in clear, so they can easily be sniffed.

Have you considered rsync? Unless your data changes dramatically from
day to day you'd probably save a lot of bandwidth and time.

HTH
John
--
Wallingford, Oxfordshire, England
We had a woodhenge here once but it rotted.

Posted by Noi on January 12th, 2004


On Sun, 11 Jan 2004 19:04:04 -0800, Adams-Blake Company thoughtfully
wrote:

I read that you're using the wget solution but I thought
I'd post an FTP solution in case you need to upload.
Executable from cron


ftp -n -i -v <<END > /home/uploadstatus.txt 2> /home/uploaderror.txt
#
# <<END defines delimiter to terminate the ftp program
# output status and errors
# open ftp site login and set transfres to binary mode
# passwd and date variables from commandline
# but one could declare 2=$(date -I)
#
open ftp.siam.com
user noi $1
bin
#
# rename previous index.html to current date
# change to pics directory and delete all files
# reload permanent files
#
rename index.html index.$2
cd /pics
lcd /home/public/pics
mdelete *.*
mput *.png
mput *.jpg
mput *.gif
cdup
lcd /home/upload
put index.html

mls / /pics /home/uploaded.txt
mget index.2003*
mdelete index.2003*
quit
END


--
------------------------------------------------------
Linux registered user #302812
using Fedora Core 1 kernel 2.4.22-1.2115.nptl
------------------------------------------------------


Posted by Vilmos Soti on January 18th, 2004


Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> writes:

Look into ftp. Check the manpage and search for .netrc which let's you
automate ftp sessions.

Vilmos

Posted by Frank da Cruz on January 19th, 2004


In article <87llo683gi.fsf@localhost.localdomain>, Vilmos Soti wrote:
: Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> writes:
:
:> I'm looking for a script that will login to my remote (dedicated) server
:> (running Linux of some flavor) from my home machine and download a file and
:> then log off and cut the connection.
:
: Look into ftp. Check the manpage and search for .netrc which let's you
: automate ftp sessions.
:
But read this first:

http://www.columbia.edu/kermit/ftpscripts.html

- Frank

Posted by Kirk Strauser on January 19th, 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-01-12T03:04:04Z, Adams-Blake Company <atakeoutcanton@adams-blaketakeout.com> writes:

Does it *have* to involve FTP? Could you use sftp or scp instead?
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFADAPM5sRg+Y0CpvERAmzIAJ498E9tlBx0U5FTxSxrrt S801iIfgCgpCWP
rx9xYxs3wlLX4it5z1RDWeY=
=W3Xz
-----END PGP SIGNATURE-----


Similar Posts