use strict; use File::Find; use MIME::Base64; sub loadFiles(); #udf sub mySub(); #udf my @files = (); my $dir = shift || die "Argument missing: directory name\n"; my $finalLoc; my $filePath; my $fileContents; my $base64EncFile; my $domain="TEST"; my $devFilePath; my $deviceDir; my $position; my $user="USER"; my $encPwd="VVNFUjEyMw=="; my $decPwd; loadFiles(); #call foreach (@files) { $filePath = $_; #replace / to \ in the directory path $filePath =~ s/\//\\/g; $devFilePath = $_; # replace \ to / when setting a file path into the target location $devFilePath=~ s/\\/\//g; $position = index($devFilePath, "RPDM"); #take a substring after the RPDM location and add that to the string below $deviceDir = "local:///".substr($devFilePath, $position); #open a file using FILE handle open( FILE, "< $filePath" ); # take all file contents into a variable $fileContents = do { local $/; }; #base-64 encode the file contents and store into a variable $base64EncFile = encode_base64($fileContents); #flatten the string by removing characters $base64EncFile =~ s/[\x0A\x0D]//g; #save the web service request into a variable my $dpString = "".$base64EncFile.""; #decode the above encoded password $decPwd=decode_base64($encPwd); #make a curl command to submit the web-service request at the destination end-point system('C:\\apps\\curl-7.15.0\\curl.exe -# -k -u admin:$decPwd --data-binary $dpString https://host:1234/services/endPoint'); close(FILE); } sub loadFiles() { find( \&mySub, "$dir" ); #custom subroutine find, parse $dir } # following gets called recursively for each file in $dir, check $_ to see if you want the file! sub mySub() { push @files, $File::Find::name if (/(\.xml|\.xsl|\.xslt|\.ffd|\.dpa|\.wsdl|\.xsd)$/i) ; # modify the regex as per your needs or pass it as another arg }