LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2015, 04:33 PM   #1
deepblue_86
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Rep: Reputation: Disabled
creating loop within ftp session for fetching data


Code:
echo "which stations you want to download (example input, brmu ankr) ? : " 
read stations
echo "which years interval (example input, 2013 2015 or 2010 2010)? :"
read year
echo "which days of year (example 001 010 or 025 025)? :"
read doy
stringarray_1=($stations)
stringarray_2=($year)
stringarray_3=($doy)
echo "connecting the ftp to fetch data"
echo
HOST='x.x.edu'
USER='anonymous'
PASSWD='12345'
ftp -n $HOST  <<END_SCRIPT 
quote USER $USER
quote PASS $PASSWD
binary

END_SCRIPT
I need to create a nested loop inside ftp to allow me fetch data, for example, inputs are;

stations=ankr brmu

year=2013 2014

doy=001 002
w.r.t. these inputs I need to create loop like;

Code:
cd 2013;cd 001;mget *;cd ..

cd 002;mget *;cd ..;cd ..

cd 2014; cd 001;mget *;cd ..

cd 002;mget *
How can I create such a loop inside ftp?
 
Old 06-30-2015, 04:46 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,267

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
seems like scp/sftp/sshfs would be safer and easier ?
 
Old 06-30-2015, 05:03 PM   #3
deepblue_86
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Is there any example related this issue in scp/sftp/sshfs?
 
Old 06-30-2015, 05:06 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,267

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
Code:
scp user1@host1:/whatever/floats/your/boat user2@host2:/whatever/grinds/your/gears
 
Old 06-30-2015, 08:18 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,386

Rep: Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087
Assuming you have can login to the server via ssh then schneidz method would be easier since the command to get the files would be

dir1=/../$year/$day (etc...)
dir2=...
scp user@host:/$dir1/ . (The . means to transfer the files to the current working directory.)
scp user@host:/$dir2/ .

Additional code would be required to parse for year intervals and knowing the absolute path to the ftp directories. However, since you are logging in as anonymous then maybe not. Once you are logged in via ftp you are limited to using its command set. Just brainstorming one way would be to create your loop outside the herdoc (i.e. everything enclosed by <<end_script end_script) and run it over the year interval or whatever. Create a variable for each directory as above and then

Code:
foreach year do (just psuedo code)
dir=/../$year/$doy/..
HOST='x.x.edu'
USER='anonymous'
PASSWD='12345'
ftp -n $HOST  <<END_SCRIPT 
quote USER $USER
quote PASS $PASSWD
binary
cd $dir
mget *
quit
END_SCRIPT
end
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
i want c program for fetching data from excel sheet rinu budhbhatti Programming 3 01-31-2011 09:23 AM
[SOLVED] linux/programming newbie: languages to learn for dynamic (data fetching) website design? Ubunoob001 Programming 16 11-25-2010 01:11 AM
Synchonizing data files and creating a NAS third data set Odyssey1942 Linux - Newbie 5 07-23-2009 07:44 AM
Creating a screen session in an existing session Frits of waterplant Linux - Newbie 4 01-18-2007 05:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration