Skip to Content
0

Move Folders containing multiple file with File adapter

Oct 17, 2016 at 10:16 PM

475

avatar image

Hi Experts,

I have requirement to move the folder containing multiple file from one File location to other location. The source application place 5 files into new folder (with date time stamp) every time and i need move all the files to SAP ECC.

I want to know if this is possible using File adapter standard function or custom code. I already got the other option using Unix script but i want to avoid the script if any standard way is available.

Thanks

Harish

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
avatar image
Former Member Oct 25, 2016 at 03:19 AM
0

Hi Harish,

How did you solve this at the end? the approach i suggested works on your case? can you update this question with final solution and close this question then it will be helpful for whoever come across this question in futere.

Regards,

Praveen.

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Hi Praveen,

Thanks for your input, unfortunately my scenario is with NFS and i used the Unix script to achieve this. The pseudocode is

move_dir ()

{

ls -1 $source_dir/Start_* >/dev/null 2>&1 ||

{

writelog "No directories to transfer"

return

}

ls -1 $source_dir | while read dirnm

do

[[ -d ${source_dir}/${dirnm} ]] || continue

tmpdirnm=${dirnm%%_*}

[[ ${tmpdirnm} = Start ]] || continue

writelog "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

echo "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

mv ${source_dir}/${dirnm} ${dest_dir}/${dirnm}

retcode=$?

if [ $retcode -eq 0 ]

then

writelog "Changing permissions for ${dest_dir}/${dirnm} to 775"

chmod -R 775 ${dest_dir}/${dirnm}

ls -1 ${dest_dir}/${dirnm} | while read file

do

writelog "File ${file} has been moved to ${dest_dir}/${dirnm}"

echo "File ${file} has been moved to ${dest_dir}/${dirnm}"

done

else

writelog "Move of ${source_dir}/${dirnm} to ${dest_dir}/${dirnm} has failed and needs investigating"

fi

done

}

The Variables needs to be defined as

basedir

source_dir

dest_dir

logdir

regards,

Harish

0
Former Member
Harish Mistri

Can't you access PI server via FTP?? is FTP not enabled in PI server?? normally FTP and SFTP are available in PI server, if available better to use FTP instead of script.

0

Harish ,

By any chance is this query related to Ariba ITK ?

Br,

Manoj

0

Hi Manoj,

Yes, this for Ariba ITK.

regards,

Harish

0

Thanks Harish . Would you mind sharing the exact script code you used , because i used this and this is not working i have defined all the required variables as well . And also channel config as well please.

0

Hi Manoj,

The script has three functions and declaration section

write log function

writelog ()

{

time_stamp=`date +%Y/%m/%d-%H:%M:%S`

echo "${time_stamp} $1" >> $logfile

}

archive function

do_archive ()

{

reten_days=35

writelog "Deleting log files older than $reten_days days." 0

find $logdir -type f -name ${scriptnm%%.sh}"log".\* -mtime +${reten_days} -exec rm {} \;

}

move dir function

move_dir ()

{

ls -1 $source_dir/Payment_* >/dev/null 2>&1 ||

{

writelog "No directories to transfer"

return

}

ls -1 $source_dir | while read dirnm

do

[[ -d ${source_dir}/${dirnm} ]] || continue

tmpdirnm=${dirnm%%_*}

[[ ${tmpdirnm} = Payment ]] || continue

writelog "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

echo "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

mv ${source_dir}/${dirnm} ${dest_dir}/${dirnm}

retcode=$?

if [ $retcode -eq 0 ]

then

writelog "Changing permissions for ${dest_dir}/${dirnm} to 775"

chmod -R 775 ${dest_dir}/${dirnm}

ls -1 ${dest_dir}/${dirnm} | while read file

do

writelog "File ${file} has been moved to ${dest_dir}/${dirnm}"

echo "File ${file} has been moved to ${dest_dir}/${dirnm}"

done

else

writelog "Move of ${source_dir}/${dirnm} to ${dest_dir}/${dirnm} has failed and needs investigating"

fi

done

}

Variable and call of function

thishost=$( uname -n )

scriptnm=$(basename $0)

basedir="base dir in which all source and target exist"

source_dir="${basedir}/file path"

dest_dir="destination dir"

logdir="${basedir}/log path"

timestamp=$(date +"%Y%m%d%H%M%S")

#support=support email address

logfile=${logdir}/${scriptnm%%.sh}"log".${timestamp}

move_dir

do_archive

exit 0

regards,

Harish

1
Ryan Crosby Oct 18, 2016 at 12:03 AM
0

Hi Harish,

Meaning you are trying to move the folder AND the five files at once? If so, then I think you would have to have a custom module to zip the contents of everything including the folder and then unzip on the other end. Since the folder is also technically a file (of sorts) but really without a payload I don't think you would have many options aside from the script or some type of custom adapter module to pool the contents into a .zip file on the sender side.

Regards,

Ryan Crosby

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Ryan,

Thanks for your reply. The custom module would be similar custom solution what we have with Unix script.

So we do not have any standard way to achieve this, the possible options are

1. Custom adapter module

2. Custom script

regards,

Harish

0

Hi Harish!

I guess you're right. Either custom OS script for copying files (without PI involved) or custom module for picking files from dynamically created folders.

Regards, Evgeniy.

1
Evgeniy Kolmakov Oct 18, 2016 at 04:02 AM
0

Hi Harish!

Do you need to transfer the folder with files to target location or to pick all files from the source folder and put it to fixed predefined folder at target side?

Regards, Evgeniy.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Hi Evgeniy,

I need to move the folder with all the files, The folder is created dynamically from the ITK Job installed on SAP PI.

regards,

Harish

0

Hi Harish,

ITK treats "default" value and "empty" values (configured in Task parameters) differently. If you want to move the folder, leave the unused parameter value as empty. I would suggest you to refer ITK guide page 31 to check the more details.

Thanks,
Pushkar

0

Hi Pushkar,

In ITK for Download Task the parameter DownloadDir is a mandatory field you can't leave it empty. ITK does create a subfolder dynamically with filePrefix paramater with appending Timestamp, inside which there would be number of CSV file depending on the event you are running. There is no way in ITK you can avoid this that's the standard behaviour of ITK.

Br,

Manoj

0

Hi Manoj,

DownloadDir parameter is applicable for download ARIBA job not for upload job.

Thanks,
Pushkar

0

Yes,the query is related to download and not upload.

0
avatar image
Former Member Oct 18, 2016 at 07:06 AM
0

Hi Harish,

Maintain * as file name scheme in the file sender adapter then adapter will pickup the files from all the folders.

Check below blog for more details.

Pick Up The Files From Dynamic Directory Using Sender File Adapter

Regards,

Praveen.

Show 8 Share
10 |10000 characters needed characters left characters exceeded

Hi Praveen!

I've just tried that. Adapter picks all files from folder but doesn't pick any file from subfolders inside parent folder.

Regards, Evgeniy.

0
Former Member
Evgeniy Kolmakov

Hi Evgeniy,

I just tested again, i have placed these two directories in the source directory which PI is polling for.

And these two folders are placed successfully in the target directory including the files.

I also mentioned all the screen shots in the blog which i tested in my system.

What is your operating system which you are placing the files? are you testing NFS or FTP?

Regards,

Praveen.

source.png (5.5 kB)
target.png (5.8 kB)
0

Hi Praveen!

I tested it on Unix NFS with PI 7.4 Dual stack.

I've seen the threads before where people used the same approach as described in your blog. Don't understand why it doesn't work in my case.

Regards, Evgeniy.

0

Hello Praveen,

Even this is not working in my case. Adapter is picking the files only from that particular folder mentioned in the Sender file adapter. Adapter is not looking the files which are inside the subfolders. I am on PO 7.4 single stack.

Regards

Om Heerani

0
Former Member
Evgeniy Kolmakov

Hi Evgeniy/Om Heerani,

This will not work for NFS protocol, i have tested with FTP protocol and it is working.

In NFS mode file adapter is ignoring the directories.

Regards,

Praveen.

0

Hello Praveen,

Thanks for info. I was trying with NFS. Will try with FTP.

Thanks.

Best Regards

Om Heerani

0

Hi Praveen!

Thanks for sharing this. This means that in case of NFS we should use another way.

Regards, Evgeniy.

0
Former Member
Evgeniy Kolmakov

Hi Evgeniy,

Normally in PI server FTP is enabled and we can use FTP instead of NFS, actually i also tested in PI server only using FTP protocol.

Regards,

Praveen.

0