PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Automatic ftp for multiple remote dir
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Automatic ftp for multiple remote dir

Réponse
 
LinkBack Outils de la discussion
Vieux 08/12/2006, 22h00   #1
pawanpgupta@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Automatic ftp for multiple remote dir

Hi all,

I want to download the one year of the data and all these data are kept
on data server in following dir structure

/2005/001
/2005/002
/2005/003
..
..
..
/2005/365

Means all files for one day is kept in seperate dirs.

Now, I want to write a shell script, which will perform automatic ftp
to the server with anonymous username and passwd (email) and download
all the files from each of the dir (each day) one by one
to one single local dir

I am trying this and have following script

#!/bin/bash

username="anonymous"
password="pawanpgupta@gmail.com"
localDir="/home/abc/downloads"
remoteDir="pub"
hostname="ftp.mit.edu" # for instance
mode="binary"

ftp -n -i -v "$hostname" <<EndOfSession
user "$username" "$password"
"$mode"
lcd "$localDir"
cd "remoteDir"
mget <file specification>
bye
EndOfSession
# End of script

This is working fine for one given dir name (one day) but when I tried
to run this inside loop for each dir (each day), it does not work? I do
not know why? if some body can me in this that will be great.

Also, If some body have some other script to perform similar work that
will be fine too

Pawan

  Réponse avec citation
Vieux 09/12/2006, 02h31   #2
Carbon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Automatic ftp for multiple remote dir

On Fri, 08 Dec 2006 14:00:46 -0800, pawanpgupta wrote:

> Hi all,
>
> I want to download the one year of the data and all these data are kept
> on data server in following dir structure
>
> /2005/001
> /2005/002
> /2005/003
> .
> .
> .
> /2005/365
>
> Means all files for one day is kept in seperate dirs.
>
> Now, I want to write a shell script, which will perform automatic ftp
> to the server with anonymous username and passwd (email) and download
> all the files from each of the dir (each day) one by one
> to one single local dir
>
> I am trying this and have following script
>
> #!/bin/bash
>
> username="anonymous"
> password="pawanpgupta@gmail.com"
> localDir="/home/abc/downloads"
> remoteDir="pub"
> hostname="ftp.mit.edu" # for instance
> mode="binary"
>
> ftp -n -i -v "$hostname" <<EndOfSession
> user "$username" "$password"
> "$mode"
> lcd "$localDir"
> cd "remoteDir"
> mget <file specification>
> bye
> EndOfSession
> # End of script
>
> This is working fine for one given dir name (one day) but when I tried
> to run this inside loop for each dir (each day), it does not work? I do
> not know why? if some body can me in this that will be great.
>
> Also, If some body have some other script to perform similar work that
> will be fine too


carbon@tux:~$ for x in $(seq -w 001 365); do echo /2005/$x; done

/2005/001
/2005/002
/2005/003
..
..
..
/2005/365

  Réponse avec citation
Vieux 09/12/2006, 07h10   #3
Adam Price
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Automatic ftp for multiple remote dir

On 8 Dec 2006 14:00:46 -0800, pawanpgupta@gmail.com wrote:

> Hi all,
>
> I want to download the one year of the data and all these data are kept
> on data server in following dir structure
>
> /2005/001
> /2005/002
> /2005/003
> .
> .
> .
> /2005/365
>
> Means all files for one day is kept in seperate dirs.
>
> Now, I want to write a shell script, which will perform automatic ftp
> to the server with anonymous username and passwd (email) and download
> all the files from each of the dir (each day) one by one
> to one single local dir
>
> I am trying this and have following script
>
> #!/bin/bash
>
> username="anonymous"
> password="pawanpgupta@gmail.com"
> localDir="/home/abc/downloads"
> remoteDir="pub"
> hostname="ftp.mit.edu" # for instance
> mode="binary"
>
> ftp -n -i -v "$hostname" <<EndOfSession
> user "$username" "$password"
> "$mode"
> lcd "$localDir"
> cd "remoteDir"
> mget <file specification>
> bye
> EndOfSession
> # End of script
>
> This is working fine for one given dir name (one day) but when I tried
> to run this inside loop for each dir (each day), it does not work? I do
> not know why? if some body can me in this that will be great.
>
> Also, If some body have some other script to perform similar work that
> will be fine too
>
> Pawan


I know this doesn't with the script, but have you looked at wget? If
it is installed it will do all of this for you in one or two lines.

cd /home/abc/downloads
wget -m ftp://ftp.mit.edu/$remoteDir

Where remotedir is /x/y/2005 not /x/y/2005/1
That way wget will handle the recursion etc.
The whole directory structure will be mirrored locally.
Does that ?
Adam
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10277 seconds with 11 queries