The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
DJ Sweet 0.9.7 (Default branch) iBot Software Releases - RSS News 0 12-10-2008 06:10 AM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 04:17 AM
Sweet Home 3D: version 1.4 released iBot Software Releases - RSS News 0 10-10-2008 01:10 AM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 12:25 PM
Abyss: a small, sweet Web server iBot UNIX and Linux RSS News 0 02-21-2008 12:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-10-2009
sitesbyjoe sitesbyjoe is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
My first FTP bash script - sweet!

Hey - thanks for reading this!

I just finished my first bash script that will handle daily ftp downloads for me, but I'm certain it could use some improvement.

Its job is to download IDX data from an ftp host (which is 24 hours behind) and I download a mix of *.txt.gz file and .tar files.

There are also "old" archives that I want to ignore.

Here's the code (its works fairly well though I get an occasional timeout)

Code:
#!/bin/bash

clear

USER="my_username"
PASS='my$password'
FTPSERVER="idx.fnismls.com"

YESTERDAY=$(TZ=EST26EDT date +%Y%m%d)
#echo $YESTERDAY

FILE1="pics-commercial-industrial-$YESTERDAY.tar"
FILE2="pics-condo-townhouse-$YESTERDAY.tar"
FILE3="pics-lots and land-$YESTERDAY.tar"
FILE4="pics-multi family-$YESTERDAY.tar"
FILE5="pics-residential-$YESTERDAY.tar"
#echo $FILE

ftp -i -n $FTPSERVER << EOF
user $USER $PASS

cd /IDX2

bin

mget *.txt.gz
get $FILE1
get $FILE2
get $FILE3
get $FILE4
get $FILE5

bye
I'd love to know what some things are I can do to improve this in the event of errors etc...

Thanks so much!!!
  #2 (permalink)  
Old 01-10-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by sitesbyjoe View Post
Here's the code (its works fairly well though I get an occasional timeout)

Code:
#!/bin/bash

clear

USER="my_username"
PASS='my$password'
FTPSERVER="idx.fnismls.com"

YESTERDAY=$(TZ=EST26EDT date +%Y%m%d)

Changing the TZ variable is an unreliable method of getting yesterday's date.
Quote:
Code:

#echo $YESTERDAY

FILE1="pics-commercial-industrial-$YESTERDAY.tar"
FILE2="pics-condo-townhouse-$YESTERDAY.tar"
FILE3="pics-lots and land-$YESTERDAY.tar"
FILE4="pics-multi family-$YESTERDAY.tar"
FILE5="pics-residential-$YESTERDAY.tar"
#echo $FILE

ftp -i -n $FTPSERVER << EOF
user $USER $PASS

You should put the username and password in your ~/.netrc file.
Quote:
Code:

cd /IDX2

bin

mget *.txt.gz
get $FILE1
get $FILE2
get $FILE3
get $FILE4
get $FILE5

bye
I'd love to know what some things are I can do to improve this in the event of errors etc...

The ftp command is not well-suited to scripting; error handling is one of it weaknesses. For scripting, if you can't use scp (recommended), use the ncftp suite of commands.
  #3 (permalink)  
Old 01-10-2009
Ishikawa Ishikawa is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
You could have it read url's from a seperate file until it reaches the end of the file.
Closed Thread

Bookmarks

Tags
bash, ftp

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0