FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 3rd, 2003, 07:49 PM
dshaw21369 dshaw21369 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 12 dshaw21369 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
FTP using specific multiple directories

Hi, How can I open the ftp connection 1 time and then get the files from the specified directories from
my control file, put these to my local server in the specified location from the control file
and then close the connection at the end?
my script is opening and closing the connection for each file in the control file and hanging up often.
Thanks!

export TERM=vt100
CurrDate=`date +%Y%m%d%H%M%S`
Logfile=/home/Log.$CurrDate
temp="/home//temp"
controlfile="/home/ftp.ctl"
newline=\\n
filepattern="*"
ipaddress="xxx.xx.xx.xx"
userid="xxxxxxxx"
password="xxxxxxxx"
trap '' 1 2 3 4 5 6 13 15 18 24 29
if ls "$controlfile" > /dev/null
then
for file in `cat $controlfile | cut -d: -f3 `
do
localdir=`cat $controlfile | grep "$file" | cut -d: -f2`
remotedir=`cat $controlfile | grep "$file" | cut -d: -f3`
tempdir=`cat $controlfile | grep "$file" | cut -d: -f1`

cd $localdir
if ping -c 3 $ipaddress > /dev/null
then
{
echo "
open $ipaddress
user $userid $password
cd $remotedir/Pending
ascii
dir *.in listfile
mget *.in
quit
"
} | ftp -i -n

else
clear
rm $temp/filename
rm $file/filelist
exit 8
fi
if ls "$tempdir/listfile" > /dev/null
then

for x in `cat $tempdir/listfile | cut -c 40-100`

do


cd $localdir
ls > filelist1

d=`date`
if ! cat filelist1 | grep "$x" > /dev/null
then
echo "Please check" $x "is missing or cannot be located ">> $Logfile
temp=`not_successful`
else

echo "Got the file " $x >> $Logfile

{
echo "
open $ipaddress
user $userid $password
cd $remotedir/Pending
rename $x $remotedir/Archive/$x
quit


"
} | ftp -i -n

fi
done

rm $tempdir/listfile
if ls | grep "filelist1" > /dev/null
then
rm $localdir/filelist1
fi
fi
y=`date +%Y%m%d%H%M%S`
echo "timestamp" $y$newline >> $Logfile
done
else
echo "*********************Control file is missing****************"
exit 8
fi


if temp=`not_successful`
then
echo "Please check $Logfile for files not transferred" |mailx -s "FTP ERROR" myemail@yahoo.com
else
echo "FTP was completed successfully " >> $Logfile
echo "FTP was completed successfully "
fi

exit

Reply With Quote
  #2  
Old February 5th, 2003, 02:27 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
Only had a short glance at your code. I am not into reading that much of code in my free time...

Suggestion: open a named pipe (instead of your unnamed one aka "|") to the ftp server and redesign your loops. then you can supply several commands for one connection.
eg.:
Code:
mknod ... /tmp/ftppipe (look up the syntax in "man mknod")
ftp -i -n </tmp/ftppipe >/tmp/ftppipe &
... add ftp connect and login commands here ...
for $i in ...; do
  echo "cd $i" >/tmp/ftppipe
  echo "get file.dat" >/tmp/ftppipe
done
echo "bye" >/tmp/ftppipe
rm -f /tmp/ftppipe

assume this to be some kind of pseudo-code and being untested. i take no responsibility if you delete all your files like this or whatever
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > FTP using specific multiple directories


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway