About FTP file upload get Stream object null value problem

Source: Internet
Author: User
Tags ftp connection ftp file ftp client

The tool class that was written a few days ago, and the Ftp.storefilestream that appeared at the time of the new test did not get the stream object. The wait time problem occurs.

Tracking code, login No problem! Go to FTP to see some directory structure and files. The discovery file has been created, but there is no content inside. An estimate is the reason that the stream object cannot write to the content.

For this question to see some of the information on the Internet, and then compare some of their own code. Found themselves after landing did not do exit and disconnect processing, plus these after the problem solved.

Here's the code:

1  Public Static Booleanputfiletoftp (File file,string newfilepathname) {2         BooleanFlag =false;3         //Create an FTP client4FtpClient FTP =getclient ();5          Try {6              //Login7 Ftp.connect (Rehostname, Integer.parseint (report));8Flag =Ftp.login (Reusername, Repassword);9                 if(flag) {Ten                     //Set upload directory One Ftp.enterlocalpassivemode (); AFtp.setcharset (Charset.forname ("UTF-8")); -Ftp.setcontrolencoding ("UTF-8"); -                   //set File type (binary) the Ftp.setfiletype (ftpclient.binary_file_type); -                   //file Stream Output -OutputStream OS = Ftp.storefilestream (retrumpetheserver+ "/" +newfilepathname); -                     if(os!=NULL){ +FileInputStream FIS =Newfileinputstream (file); -                         byte[] B =New byte[1024]; +                         intLen = 0; A                          while(len = Fis.read (b))! =-1) { atOs.write (b,0, Len); -                         } - fis.close (); - os.close (); - ftp.logout (); -Flag =true; in}Else{ - ftp.logout (); to                         return false; +                     } -}Else{ the Ftp.disconnect (); *                     return false; $                 }Panax Notoginseng                  -                  the}Catch(IOException e) { + e.printstacktrace (); A                 return false; the}finally {  +                 Try {  - Ftp.disconnect (); $}Catch(IOException e) { $ e.printstacktrace (); -                     Throw NewRuntimeException ("Close FTP connection exception occurred! ", E);  -                 }  the             } -          returnFlag; Wuyi}

The above is the code and may not be considered comprehensive enough. Please use it carefully!

About FTP file upload get Stream object null value 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.