cancel
Showing results for 
Search instead for 
Did you mean: 

Read or Write File On FTP server based on another file existence.

Former Member
0 Kudos

HI PI Techies,

I have a scenario where I need to read a File from FTP server based on existence check of another File on the same location of FTP.

Secondly I have a reverse scenario to write a File on FTP server and need to write a Marker File Followed by this File on same FTP Folder.

Can we think of these?

Runtime OS Command before\After Message Processing ( our PI server is AIX OS) ?

( Does it work with FTP server)

or

Adapter Module ( Does it work with FTP)?

Please suggest the possible ways with steps.

Regards,

Anurag

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

An idea, can be:

READ

- Sender FTP channel based on file existance (file must be empty - at receiver side, do not create empty file)

- OS Script Move file to a "OUTQUEUE" directory

- A sender Channel or directly the OS Script, to trasfer the file

WRITE

- Classical Sender-Receiver File Channels

- An OS script (in Receiver Channel) to create the marker file in destination folder

Former Member
0 Kudos

Thanks for your reply.

What I understand from OS command is that it applies only to the Operating server of PI server and we can play with File at Pi server only not to the remote server.

Am I right?

Regards,

Anurag

Former Member
0 Kudos

Yes, exactly... because OS command can't be executed in FTP session...

However, you can run all script in PI server, trasferring file in and out.

Former Member
0 Kudos

Hi Anurag,

Read:

1. Sender channel to FTP server to pick the other file and corresponding receive channel to place it in some local directory of PI server

2. In the receiver channel OS command line after message processing call unix shell script which can do a SSH login to FTP server and SCP the file from FTP server to local PI directory

3. Another sender channel to pick the actual file and process it.

Write:

1. Create two receiver channels, one for data file and other file marker file.

2. In the interface determination, add two receiver interfaces for a single sender interface and check the option u201CMaintain order at run timeu201D also create two receiver agreement for each channel.

3. Here the first is for data file and next is for marker file.

4. If you want to write a zero byte file as your marker file you can avoid passing the data from outbound interface to inbound interface.

Hope this will help you.. But here the Unix script actually login to the FTP server and picks the file. Let me know if you need more help on how to do the shell scripting and how to call in command line of channel 

Former Member
0 Kudos

Hi,

For the File read, you can try the following approach.

Use the sender file adapter to pick the marker file from the directory and start the interface. Then, use the Java FTP File i\o functionality to pick the actual file. You can either do this in an adapter module or in a Java mapping in the ESR. Java mapping would be better as you'll have more trace and monitoring capabilities than an adapter module. For the ob service interface, remeber to select option "XI 3.0 compliant"

If you decide on an adapter module, then in the process() method, use java file i\o to read the file, convert it to a byte stream and replace this as the payload output from the adapter module.

For the Write functionality, Stephen's suggestion below is the best approach.

Regards

Former Member
0 Kudos

Hi Shiladitya,

Thanks for your reply.

For Sender Case you suggested to start the interface("Use the sender file adapter to pick the marker file from the directory and start the interface.") after picking marker File but how would picking marker File bv a FTP Adapter initiates another scenario to pick the actual Data File From FTP server? What will be the link between two scenarios ?

Please describe more.

Thanks,

Anurag

Former Member
0 Kudos

Hi Stephen,

Thanks for your reply.

For Read Case:

I have never done shell scripting.

Please suggest the way and code to do FTP from shell script through FTP Adapter and pick the file.

Our PI OS is AIX server.

Write:

If I take two receiver interfaces and select maintain order at runtime. Then will it take care that Data File is placed completely before marker File.

Please suggest.

Regards,

Anurag Garg

Former Member
0 Kudos

Hi,

The scenario would be a single scenario. On the sender file adapter, you pick the marker file to start the scenario. Then, either in an adapter module or java mapping, you will retrieve the actual file to replace the payload of the marker file (presume here that the marker file is a zero byte file or one whose actaul payload is irrelevant). You will have two receiver interfaces, one for the marker, other for the actual file. Choose option "maintain order at runtime" so that the marker file is always posted before the actual file.

Former Member
0 Kudos

I Anurag,

For FTP and move to a archive directory, this can be an OS Shell Script sample:

cd /$1
ftp -n -v <<%%EOF%%
open $2
user $3 $4
prompt
asci
cd $5
mput $7*
bye
%%EOF%%

mv $7* /$1/archive

You can pass parameters to $ character, like follow in the File Adapter CommChannel:

sh ShellSampleScript.sh directory_source hostname FTPUsername FTPPassword directory_destination .....

If you need an AdHoc ShellScript.. tell what you want and we can try to accomodate you!

Former Member
0 Kudos

Hi ,

Thanks for reply.

I am looking for shell script with following reuirement:

1) Open FTP connection with inputs( FTP server hostname , userid, password,port) .

2)Take Input for Source Directory and check if MarkerFile.csv exists.

a) If exists, delete MarkerFile.csv and handover the call to FTP Adapter to pick the Actual Data File from FTP server.

b) If doesn't exists. exit the Adapter.

Regards,

Anurag Garg

Former Member
0 Kudos

1) FTP CONNECTION with parameters $1 => Hostname || $2 => Username || $3 => Password

ftp -n -v <<%%EOF%%
open $1
user $2 $3
prompt
asci
bye
%%EOF%%

2) CHECK IF MARKER EXIST $4 => Input File Directory || $5 => Marker Filename (Subsequently, it get file to PI current local directory then, send with the FileAdapter)

cd $4
if [ -s $5 ]; then
mget $5
else
echo NoFile $5
fi

Answers (1)

Answers (1)

Former Member
0 Kudos

For Read:

You may use a sender channel to reader the marker file and another Sender channel to read the acutal data file and use BPM.

For Write:

This can be achieved by using one receiver channel (depending on the FCC) or two receiver channel.

Thanks