liv2luv has asked for the wisdom of the Perl Monks concerning the following question:
Appreciate the help. Thank you.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 stri +ng 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 $/; <FILE> }; #base-64 encode the file contents and store into a variable $base64EncFile = encode_base64($fileContents); #flatten the string by removing <CR><LF> characters $base64EncFile =~ s/[\x0A\x0D]//g; #save the web service request into a variable my $dpString = "<env:Envelope xmlns:env='http://schemas.xmlsoap.or +g/soap/envelope/' xmlns:dp='http://www.datapower.com/schemas/manageme +nt'><env:Body><dp:request domain='$domain'><dp:set-file name='$device +Dir'>".$base64EncFile."</dp:set-file></dp:request></env:Body></env:En +velope>"; #decode the above encoded password $decPwd=decode_base64($encPwd); #make a curl command to submit the web-service request at the dest +ination end-point system('C:\\apps\\curl-7.15.0\\curl.exe -# -k -u admin:$decPwd --d +ata-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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Windows Curl.exe in Perl
by syphilis (Archbishop) on Apr 24, 2012 at 23:30 UTC | |
by liv2luv (Initiate) on Apr 26, 2012 at 12:57 UTC | |
by Anonymous Monk on Apr 26, 2012 at 13:14 UTC | |
by liv2luv (Initiate) on May 02, 2012 at 20:43 UTC | |
by Anonymous Monk on May 04, 2012 at 12:57 UTC |