LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices



Reply
 
Search this Thread
Old 03-20-2014, 06:55 AM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Rep: Reputation: Disabled
Downloading file from FTP server to Unix box


Hello,

I am writing one script for automation purpose in that i am downloading one file from FTP server[Windows] to unix box.

I have written most of the code only part left is checking availability and downloading.

we get file once in a week at FTP Server some name like "ABCD-23220140303" at anytime on any day.

so purpose is to pick the newly file arrived and ignores the previous week file so here previous week file will be like ""ABCD-23220140302" and the next week file will be "ABCD-23220140304".

Script will run daily and just check the file if newly file arrived will pick else will written log no new file available.

written some piece of code.

Appreciate your assistance here.
 
Old 03-20-2014, 08:52 AM   #2
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Debian, OS X (bsd)
Posts: 156

Rep: Reputation: 30
wget should be able to do the job. Hopefully it is Anonymous FTP, in which case you just point it at the URL for the file.
 
Old 03-20-2014, 09:41 AM   #3
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 15,078

Rep: Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713
Quote:
Originally Posted by azheruddin View Post
Hello,

I am writing one script for automation purpose in that i am downloading one file from FTP server[Windows] to unix box. I have written most of the code only part left is checking availability and downloading.

we get file once in a week at FTP Server some name like "ABCD-23220140303" at anytime on any day. so purpose is to pick the newly file arrived and ignores the previous week file so here previous week file will be like ""ABCD-23220140302" and the next week file will be "ABCD-23220140304".

Script will run daily and just check the file if newly file arrived will pick else will written log no new file available. written some piece of code.
Since you've written the script, why don't you post it here, so we can see what is going on? You tell us what you want to do, but don't tell us what you've tried/done, or show us what error(s) you're getting.
 
Old 03-21-2014, 01:46 AM   #4
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
No wget installed and i have no option to installed,running on AIX.
I dont have option other than FTP.
Iam connecting with some credentials not Anonymous user.

About the requirement...

1. The file is coming like "ABCD-23220140303" at FTP server once in a week.

2. script will run on daily basis and will pick up and download the file to Aix machine if file is available.

3. Script will check status of file on daily basis, if file is available it should download.

the file name is like varies for each week like..

1st week....ABCD-23220140301
2nd week....ABCD-23220140302
3rd week....ABCD-23220140303
4th week....ABCD-23220140304
 
Old 03-21-2014, 02:32 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Show us what you've scripted and what the problem(s) are.
 
Old 03-21-2014, 03:06 AM   #6
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
This is i have written
get_file ()
{
ftp -vn $Server_ip <<EOF
user $username $password
pass
bi
lcd $target_directory
cd $source_directory
get $ftpfile
bye
EOF

So the problem is...

1. New file availability checking
2. how to pick the recent one and ignores the rest.
 
Old 03-21-2014, 05:24 AM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Well, it depends on what the numeric part signifies I guess, but you could do an ftp ls and compare 'new' list to 'current' list (both sorted of course).
If the new list is longer, fetch the new entry.
Assuming the number is some sort of serial or datetime, you can check to see if you've got it already.
Basically only you can specify the requirement, especially if the 2 lists are not necessarily the same length at any given time.

In fact, you just need to diff the lists, favouring the new list over the old ie what appears on the new and not in the old.
Could be stored in a flat file I think; once a week is only 52 files a year.
Append each new filename as you retrieve it.

Last edited by chrism01; 03-21-2014 at 05:42 AM.
 
Old 03-21-2014, 07:02 AM   #8
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Thnaks Chris you got my concern,I was expecting a some Piece of Code for listing the files and comparing with the the new one...
 
Old 03-21-2014, 07:45 AM   #9
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Appreciate if anyone has having other approach rather than listing and comparing...
 
Old 03-22-2014, 05:38 AM   #10
azheruddin
Member
 
Registered: Dec 2011
Posts: 56
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
can anyone suggest on my request.
 
Old 03-22-2014, 05:30 PM   #11
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 15,078

Rep: Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713
Quote:
Originally Posted by azheruddin View Post
Thnaks Chris you got my concern,I was expecting a some Piece of Code for listing the files and comparing with the the new one...
chrism01 posted a suggest that's easily implemented. Read the man page on the diff command.
Quote:
Originally Posted by azheruddin
Appreciate if anyone has having other approach rather than listing and comparing...
..and...
Quote:
Originally Posted by azheruddin
can anyone suggest on my request.
You were given a suggestion...coming back to bump your own thread after less than 24 hours is fairly rude. And, you were asked what input you were getting, but didn't post it. Unless you provide details, there's little else anyone can suggest. And why are you not using SFTP/SCP, which would make scripting MUCH easier?
 
Old 03-27-2014, 02:34 PM   #12
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 1,554

Rep: Reputation: 241Reputation: 241Reputation: 241
If the ls output of the ftp server includes the timestamp you can list and shorten the list based on that criteria. I dealt with an NT service that grabbed things off of an ftp server a decade-ish ago. I modified it to make sure that the last written timestamp was > a minute old, as it tended to grab files before they had been fully uploaded. Hopefully the file in question is in a dedicated directory to limit the output of ls.
 
  


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
[SOLVED] Which Distro for File Server and FTP - Old box or New? Steel_Penguin Linux - Distributions 5 01-11-2011 11:00 PM
Getting error in ftp from windows to unix box sangeeta_linux Programming 5 03-18-2009 09:18 PM
FTP connection, uploading and downloading files through Shell between unix and linux alertroshannow Linux - Newbie 2 02-16-2009 02:00 AM
How does file downloading happen in HTTP and FTP seidren General 4 11-09-2003 09:59 AM
ftp-server error when downloading rpm's Mikessu Mandriva 2 09-18-2003 07:46 AM


All times are GMT -5. The time now is 05:53 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration