s ftp = ##class(%Net.FtpSession).%New() – FTP ftp.Timeout = – ftp.Connect(, , , ) – FTP ftp.SetDirectory() – FTP ( ) ftp.List( , ) – , , ftp.Binary() – ftp.Retrieve(, .GlobalStream) – ftp.Delete() – ftp.Append(, ) - ftp.Logout() – FTP
ClassMethod FTPGetFiles(ftp, fileName) As %Status { s ftp = ##class(%Net.FtpSession).%New() s ftp.Timeout = 2000 s host = "11.111.11.111" s port = 2021 s user = "myth/user" s pass = "userspass" if ftp.Connect(host, user, pass, port) { d ftp.SetDirectory("/TestDir") // s fileName = "????????t??????vK*.xml" // d ..ParserDir(ftp, fileName) s fileName = "????????a??????yK*.xml" d ..ParserDir(ftp, fileName) } q ftp.Logout() } /// , ClassMethod ParserDir(ftp, fileName) As %Status { s file = "" sx = 1 s file(x) = "" // d ftp.List(fileName, .stream) q:'$IsObject(stream) while 'stream.AtEnd { // s file = stream.ReadLine(1, .sc, .eol) if ( file = $C(10) ) { // sx = x + 1 s file(x) = "" } else { // s file(x) = file(x) _ file } if $$$ISERR(sc) { w "ERROR" q } } // d ftp.Binary() // s key = $ORDER(file(""),1) while ( key '= "" ) { // s fName = $E(file(key), 40, *) if ( $L(fName) > 0 ) { #dim GlobalStream As %GlobalBinaryStream; // fName. - FTP CP1251 d ftp.Retrieve($zcvt($zcvt(fName,"I","CP1251"),"O","CP1251"),.GlobalStream) #dim status As %String; // if ( $F(fName,"s") > 0 ) { s status = ..Parser(GlobalStream, "Product", "Shipment", parser) } elseif ( $F(fName,"d") > 0 ) { s status = ..Parser(GlobalStream, "Product", "Disposal" ,parser) } if ( status ) { d ftp.Delete(fName) } } s key = $order(file(key),1) } q ftp.Logout() }
/// FTP ClassMethod RunExport() As %Status { s ftp = ##class(%Net.FtpSession).%New() s ftp.Timeout = 2000 s host = "11.111.11.111" s port = 2021 s user = "myth/user" s pass = "userspass" if ftp.Connect(host, user, pass, port) { d ftp.Binary() // s st = ##class(%SQL.Statement).%New() d st.%PrepareClassQuery("%File","FileSet") s rs = st.%Execute("/usr/cachesys201221/csp/sm/export_xml","*.xml","Size,Name") while rs.%Next() { // , d ftp.Delete(rs.%GetData(6)) // s stream = ##class(%FileBinaryStream).%New() // 1 - s stream.Filename = rs.%GetData(1) // - "done" if ( ftp.Append(rs.%GetData(6),stream) = $$$OK ) { d ##class(%File).Rename(rs.%GetData(1), ##class(%File).GetDirectory(rs.%GetData(1)) _ "done/" _ rs.%GetData(6)) } k stream } } d ftp.Logout() k ftp q $$$OK }
#server(TestProject.MakeExcelFile($("#table_to_excel").html(), "PriceList"))# ClassMethod MakeExcelFile(Data As %String, FileName As %String) As %Status { s FileName = "/tkf/reports/" _ FileName _ "_Excel.xls" s stream = ##class(%Library.FileCharacterStream).%New() s FP = $$GetFilename^%apiCSP(FileName) if ( $L(Data) = 22 ) { d stream.CopyFrom(Data) } else { d stream.Write(Data) } d stream.SetAttribute("Content-Length",stream.Size) d stream.SetAttribute("ContentType","application/excel") d stream.SetAttribute("Charset","UTF8") d stream.SetAttribute("ContentDisposition","attachment; filename=" _ $p(FileName,"/",4)) d stream.LinkToFile(FP) d stream.SaveStream() s oid = stream.%Oid() &js<window.location="#url(%25CSP.StreamServer.cls?STREAMOID=#(..Encrypt(oid))#)#";> q $$$OK }
, or you can specify the number format type: <style>.toText{ mso-number-format:\"\@\"; } </style> <td class=”toText”> </td>
Source: https://habr.com/ru/post/177609/
All Articles