cancel
Showing results for 
Search instead for 
Did you mean: 

Move Folders containing multiple file with File adapter

Harish
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

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.

Harish
Active Contributor
0 Kudos

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

former_member182412
Active Contributor
0 Kudos

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.

manoj_khavatkopp
Active Contributor
0 Kudos

Harish ,

By any chance is this query related to Ariba ITK ?

Br,

Manoj

Harish
Active Contributor
0 Kudos

Hi Manoj,

Yes, this for Ariba ITK.

regards,

Harish

manoj_khavatkopp
Active Contributor
0 Kudos

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.

Harish
Active Contributor

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

Answers (3)

Answers (3)

former_member182412
Active Contributor
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

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.

former_member182412
Active Contributor
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

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.

om_prakash7
Explorer
0 Kudos

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

former_member182412
Active Contributor
0 Kudos

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.

om_prakash7
Explorer
0 Kudos

Hello Praveen,

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

Thanks.

Best Regards

Om Heerani

former_member190293
Active Contributor
0 Kudos

Hi Praveen!

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

Regards, Evgeniy.

former_member182412
Active Contributor
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

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.

Harish
Active Contributor
0 Kudos

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

former_member183898
Participant
0 Kudos

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

manoj_khavatkopp
Active Contributor
0 Kudos

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

former_member183898
Participant
0 Kudos

Hi Manoj,

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

Thanks,
Pushkar

manoj_khavatkopp
Active Contributor
0 Kudos

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

Ryan-Crosby
Active Contributor
0 Kudos

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

Harish
Active Contributor
0 Kudos

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

former_member190293
Active Contributor

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.