Use Edtftpj-***.jar upload to download the solution and attention point of Chinese problem

Source: Internet
Author: User
Tags getmessage

Filetransferclient ftpclient =NULL; Try{ftpclient=Newfiletransferclient (); //Set remote hostFtpclient.setremotehost (ftpaddress);            Ftpclient.setremoteport (Portint);            Ftpclient.setusername (Ftpaccount);            Ftpclient.setpassword (FTPPWD); //Note: The red section below must be written before connect, as it will be assigned to the setting parameters of the FtpClient object when the Connect is done. Ftpclient.getadvancedsettings (). Settransferbuffersize (2048); Ftpclient.getadvancedsettings (). Settransfernotifyinterval (5000); Ftpclient.getadvancedsettings (). setcontrolencoding ("GBK");            Ftpclient.connect (); Ftpclient.changedirectory ("/"); Ftpclient.setdetectcontenttype (true);            Ftpclient.setcontenttype (ftptransfertype.binary); String[] Names=ftpclient.directorynamelist ();  for(String oname:names) {log.debug ("File is:" +oname); }             for(String kngattachname:kngattachs) {inti = Kngattachname.lastindexof (".")); //"." does not exist in the attachment list path.                if(I! =-1) {                    //get attachment file typeString FileType = kngattachname.substring (i + 1, Kngattachname.length ()); String LocalFilename= This. Getcspid () + "." +FileType; File File=NewFile (Fileserverpath); if(!file.exists ())                    {File.mkdirs (); } String Path= Fileserverpath + "/" +LocalFilename; File file1=NewFile (path);                    File1.createnewfile (); FileOutputStream Fos=NewFileOutputStream (FILE1); if(log.isdebugenabled ()) {Log.debug ("Local filepath is:" +path); Log.debug ("Remote host is:" + ftpclient.getusername () +
"@" + ftpclient.getremotehost () + ":" +
Ftpclient.getremoteport () + "@" +ftpclient.getremotedirectory ()); Log.debug ("Kngattachname is:" +kngattachname); } String Kngattachname_ecode=NewString (Kngattachname.getbytes (), "UTF-8"); if(Ftpclient.exists (Kngattachname_ecode)) {Final intBuffer_size = 2048; Final byte[] buffer =New byte[Buffer_size]; intBytesread = 0; Filetransferinputstream InputStream=NULL; Try{InputStream=Ftpclient.downloadstream (Kngattachname_ecode); while((bytesread = inputstream.read (buffer, 0, buffer_size))! =-1) {fos.write (buffer,0, Bytesread); } fos.flush (); } Catch(IOException e) {if(log.isdebugenabled ()) {Log.error ("Knowledge attachment Download to file" + kngattachname + "Server FTP exception" +
E.getmessage (), E); } String Message=NewStringBuilder ("The Kngaffix").
Append (Kngattachname). Append ("transfailed!"). toString (); Soaputil.recordlog ("Transfail", message); } finally { if(InputStream! =NULL) {inputstream.close (); } if(Fos! =NULL) {fos.close ();//must is closed to complete the transferioutils.closequietly (FOS); } } } Else{log.error (The attachment ("+ Kngattachname +") of the Kngid ("+ + +") does not exist! "); } //Knowledge Attachment ObjectDataObject Affixobject =NewDataobjectsupport (
"Com.huawei.csp.customization.kbs.domain", "C_kbs_kngadjunctinfoedit"); Affixobject.setstring ("Adjid", This. Getcspid ()); Affixobject.setstring ("Kngid", Kngid); Affixobject.setint ("Versionnum", 0); Affixobject.setint ("Adjclass", 2); intj = Kngattachname.lastindexof ("/"); if(J! =-1) {affixobject.setstring ("Adjname", Kngattachname.substring (j + 1,
Kngattachname.length ())); } Else{affixobject.setstring ("Adjname", Kngattachname); } affixobject.setstring ("Adjpath", Kngattachpath + "/" + Datedirpath
+ "/" +localfilename); Affixobject.setstring ("Adjtype", FileType); Affixobject.setint ("Adjsize", 0); String StaffID= This. Tabledataaccessservice.
Getsystemparam ("107", "107993"). GetValue (); Affixobject.setstring ("Creatorid", StaffID); Affixobject.setstring ("Modifierid", StaffID); Affixobject.setstring ("Hostedccid", "001"); Affixobject.setint ("OrderId", 1); This. Collectknginterface.addkngaffix (Affixobject); } Else{String message=NewStringBuilder ("The Kngaffix file type error!"). toString (); Soaputil.recordlog ("Transfail", message); }} retint= (0); } Catch(Exception e) {log.error (E.getmessage (), E); } finally { if(FtpClient! =NULL&&ftpclient.isconnected ()) { Try{ftpclient.disconnect (); } Catch(IOException ioex) {log.error (Ioex.getmessage (), IOEX); } Catch(ftpexception Ftpex) {log.error (Ftpex.getmessage (), Ftpex); } } }

This article transferred from: http://blog.sina.com.cn/s/blog_5b254b7701014qbd.html

Use Edtftpj-***.jar upload to download the solution and attention point of Chinese problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.