[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ftpapi] Need to understand how decode from Base64 to Ascii



Hi list,
i'm using BASE64 service program to decode a base64 string who contains ascii
data. My goal is to write the data to a txt file on the ifs, a file who should
be ASCII and not EBCDIC since it will serve other two applications windows based.

What am i missing?

This is a snippet from my code:

d FilePtr         s               *   Inz(*Null)
D File            s          65535A   Based(FilePtr)
 *
D bytesToDec      s              4A   Inz
D decbuf          s              3a   Inz
d declen          s             10i 0 Inz
D fd              s             10i 0 Inz
D rc              s             10i 0 Inz
d pathToFile      s             80a   Inz
 *
d C_pathToXML     c                   '/BNL'
d Path2           c                   '/Req/XML/BNL'
d MAV             c                   'MAV'
d RH              c                   'RH'

/free
 *INLR=*On;
 pathToFile=C_PathToXml + '/' + MAV + '/' +
            MAV  + '_' + %Trim(%Char(TBNL.BFIbnl)) + '_' +
            %Char(%dec(TBNL.BFDTA1)) + '_' + %Char(%dec(TBNL.BFDTA2)) +
             '.txt';

 Count = %Size(File) * 100;
 FilePtr = %Alloc(Count);

 //do stuff here that put base64 string into File variable

 fd = openf((%trim(pathToFile))
             : O_CREAT + O_EXCL + O_WRONLY
             + O_TEXTDATA + O_TEXT_CREAT + O_CCSID
             : S_IRUSR + S_IWUSR
             : 819
             : 0);
 If fd < 0;

   //write error to log file
  return;

 Else;

  //Take File variable 4 bytes per time and decode them
   DoW %Len(%Trim(File)) > 0;
     BytesToDec = %subst(File:1:4);
     If %len(%Trim(File)) > 4;
       File = %subst(File:5);
     Else;

       File = '';
     EndIf;
     declen = base64_decode(%addr(BytesToDec):4
                           :%addr(decbuf):3);
     http_xlatep(declen:%addr(decbuf):TO_ASCII);
     writef(fd:%addr(decbuf):declen);
   ENDDO;

   closef(fd);

   //Write to log

 EndIf;

 Dealloc(en) Fileptr;

 Return;
/end-free


--
Luca Giammattei


---
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus



--
This message has been scanned by E.F.A. Project and is believed to be clean.


--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi