LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 03:46 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
seems like scp/sftp/sshfs would be safer and easier ?
 
Old 06-30-2015, 04: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, 04:06 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
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



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 08:23 AM
[SOLVED] linux/programming newbie: languages to learn for dynamic (data fetching) website design? Ubunoob001 Programming 16 11-25-2010 12:11 AM
Synchonizing data files and creating a NAS third data set Odyssey1942 Linux - Newbie 5 07-23-2009 06:44 AM
Creating a screen session in an existing session Frits of waterplant Linux - Newbie 4 01-18-2007 04:53 AM

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

All times are GMT -5. The time now is 05:32 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
Open Source Consulting | Domain Registration