LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2008, 08:51 AM   #1
wademac
Member
 
Registered: Apr 2008
Posts: 43

Rep: Reputation: 19
script to automate EDI by FTP


Hello,

Trying to automate a process of getting EDI files from a remote server and download them then rename the files to the correct format so they can be used in the database

connect to the EDI by FTP and do a list command you get something like

-rw-rw-rw- 1 owner group 1062 Mar 31 15:09 A3882692
-rw-rw-rw- 1 owner group 306 Mar 31 15:09 A3882695

I would like to pull the files down and automate the rename

Conditions to consider:
1) File naming standard File type_YYMMDD.txt
Need a method to insert date into file name
2) If ftp message returned 550 No such file or directory
skip and go to next command
3) If ftp message returned 226 Transfer complete
go to next command
4) If ftp message returned 421 Timeout
go back through login process and start again
5) Above commands will group all files for each of the payment types (all dates) into 1 destination file

Need a method to run the script for each of the date's set of files or a method to only download the current day and alternate method to select missed dates.
Options:
Option 1) Have a control file with successful dates for downloads
Script to have commands such as:
If today's date > last successful date in control file
control date + 1
If today's date = control date + 1
select files with the command such as
get /bundle/any/flatfile.TYPE/20080407000000/20080407235959/TYPE_080407.txt TYPE_080407.txt
where the date in the specifications = control date + 1 Continue the process until today's date = last successful date ion control file

Option 2) Script to download only files for today's date, in the command such as
get bundle/any/flatfile.TYPE/20080407000000/20080407235959/TYPE_080407.txt TYPE_080407.txt

Then have an alternate script which could be run manually with an argument (parameter) entered for the date missed.

If more than 1 date missed, the alternate script could be run for each day that the download did not occur
 
Old 04-14-2008, 08:53 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
hmm, how much are you going to pay me to do your work?
 
Old 04-14-2008, 12:25 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Not an answer, but if you're doing this in some kind of corporate environment, and I assume the "remote" server is somewhere across the internets, then why are you using FTP? Do you want your passwords gestohlen?

Srsly, though, you should look into using Perl, which is indeed ideal for this sort of thing. I have an example of how to use basic FTP stuff in my Vim Builder script, and there are definitely better examples out there.

Besides, I don't even know what (an?) EDI is. Try yahooing for "Perl" and "Perl FTP Module" to get started. Else, if Perl isn't (in) your bag, Ruby and Python both have FTP modules, or you could just use Bash along with wget and any other commands you may need!
 
Old 04-14-2008, 12:55 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
EDI ("Electronic Data Interchange") is what businesses used for computer::computer data exchange before they invented XML ;-)

http://en.wikipedia.org/wiki/Electro...ta_Interchange

The suggestion about using Perl (for a simple, in-house solution with existing servers) is good advice.

Alternatively, you might want to consider a commercial product (especially if security is an issue):

http://www.proginetuk.co.uk/sections...net-server/66/

http://www.ibm.com/developerworks/we.../schwartz.html

ftp://ftp.software.ibm.com/software/...24-7536-00.pdf
 
Old 04-14-2008, 01:34 PM   #5
wademac
Member
 
Registered: Apr 2008
Posts: 43

Original Poster
Rep: Reputation: 19
It is a secure layout I ensure you

manually that is done like so.

ftp ftp.otherserver.xxx

ls

150 Opening data connection for mailbox contents.
-rw-rw-rw- 1 owner group 1062 Mar 31 15:09 F3882692
-rw-rw-rw- 1 owner group 306 Mar 31 15:09 F3882695
-rw-rw-rw- 1 owner group 1101 Mar 31 15:09 F3882696
-rw-rw-rw- 1 owner group 1101 Mar 31 15:09 F3882697
-rw-rw-rw- 1 owner group 718 Mar 31 15:09 F3882693
-rw-rw-rw- 1 owner group 1510 Mar 31 15:09 F3882694
-rw-rw-rw- 1 owner group 632 Mar 31 15:09 F3882690
-rw-rw-rw- 1 owner group 1914 Mar 31 15:09 F3882691

get /bundle/any/flatfile.DUL/20080409000000/20080409235959/DUL_080409.txt DUL_080409.txt
get /bundle/any/flatfile.BEO/20080409000000/20080409235959/BEO_080409.txt BEO_080409.txt

This will do what I need todo manually but we are talking a daily thing with about 10 files with different ending beside DUL BEO etc..

the format in the request 20080409235959 is year 2008 month 04 day 09 hour 23 minutes 59 seconds 59

The file format is YYMMDD.txt
Need to consider FTP time and messages like

550 No such file or directory
226 transfer complete
421 Timeout

need to run it for that day date and some how also be able to check to see if the files have run in the past couples of days and download the files.
 
  


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
Automate FTP session using Shell Script kalyanofb Programming 2 04-07-2007 08:44 AM
Automate FTP steps vinayras Linux - Software 4 03-30-2007 06:06 AM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
Kermit Script to Automate FTP SSL/TLS fiddelm3742 Linux - Software 0 05-18-2004 11:53 PM
Automate FTP noodle123 Linux - General 1 10-15-2002 04:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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