Error set-use Apache-nginx to build image server to complete image upload function

Source: Internet
Author: User
Tags ftp connection ftp login
Use Apache-nginx services to build a picture server
Use resources:
vmware+ CentOS + nginx +vsftpd
Nginx: A service that stores images. See-nginx Installation Manual
VSFTPD: Image upload Transfer Protocol. See-VSFTPD Installation Manual

Using the jar package:
Org.apache.commons.net
Package Tool Class:
Ftputil

Development code:

 Public classftptest {@Test Publicvoidtestftpclient()throwsException {//Create a FtpClient objectFtpClient ftpclient =NewFtpClient ();//Create FTP connection FTP default port number isFtpclient.connect ("192.168.137.128", +);//Log in to the FTP server, using username, passwordFtpclient.login ("Ftpuser","Ftpuser");//Upload files//Read local fileInputStream InputStream =NewFileInputStream (NewFile ("C:\\users\\public\\pictures\\sample pictures\\2.jpg"));//Set upload pathFtpclient.changeworkingdirectory ("/home/ftpuser/www/images");//Modify the format of the uploaded fileFtpclient.setfiletype (Ftp.binary_file_type);//Parameter one server file name//Parameter two upload the file InputStreamFtpclient.storefile ("Hello1.jpg", InputStream);//Close connectionInputstream.close ();    Ftpclient.logout (); }//Host FTP server hostname//Port FTP server ports//Username FTP login account//Password FTP login password//BasePath FTP Server base directory//FilePath FTP server file storage path. For example, the date of storage:/2015/01/01. The path to the file is Basepath+filepath//filename uploaded to the FTP server//input stream@Test Publicvoidtestftputils()throwsFileNotFoundException {InputStream InputStream =NewFileInputStream (NewFile ("C:\\users\\public\\pictures\\sample pictures\\2.jpg"));BooleanA = Ftputil.uploadfile ("192.168.137.128", +,"Ftpuser","Ftpuser","/home/ftpuser/www/images","/2016/02/17","Test.jpg", InputStream);    System.out.println (a); }@Test PublicvoidWriteFile()throwsFileNotFoundException {String NewFileName =NULL;//Upload the file name to the serverFtpClient FTP =NULL; InputStream InputStream =NewFileInputStream (NewFile ("C:\\users\\public\\pictures\\sample pictures\\2.jpg"));Try{FTP =NewFtpClient (); Ftp.connect ("192.168.137.128", +);//Establish connectionBooleanb = Ftp.login ("Ftpuser","Ftpuser");//Loginif(!B) System.out.println ("Failed");intReply = Ftp.getreplycode ();if(!                Ftpreply.ispositivecompletion (Reply)) {ftp.disconnect (); System.out.println ("Failed"); }/** * Set upload type, picture is binary picture by default ASCII encoding is used. Because the picture is a binary file. So to set it up or upload the picture is big Erhualian * *Booleanresult = Ftp.setfiletype (Ftp.binary_file_type); Ftp.changeworkingdirectory ("/home/ftpuser/www/images"); String FileName ="/hello1.jpg";Booleanbb = Ftp.storefile (FileName, InputStream);//Specify the file name to the server}Catch(IOException e) {System.out.println ("Failed to connect to FTP!" "); System.out.println ("Failed"); }finally{Try{if(InputStream! =NULL) Inputstream.close ();if(FTP! =NULL||            Ftp.isconnected ()) ftp.logout (); }Catch(IOException E1) {}} System.out.println ("Upload the file successfully!" "); System.out.println (NewFileName);//Returns the filename of the uploaded file}}

-Pit Daddy wrong

    • Error description
      • Using Xshell and xftp to connect to Linux is no problem, the tool transfer files is not a problem, except the use of code to complete the upload times wrong. And the Linux server sometimes generates the corresponding folder path, but there is no file.
      • Using VMware to run Nginx and VSFTPD, began to suspect that the Linux port or the Linux firewall did not open the cause of transmission failure to open 2 Linux virtual machines. The result is still error. The Nginx and VSFTPD services are then reinstalled. Error remains.
    • Cause of Error:

    • Native Windows Firewall is not off!!! Hang Daddy ...
    • The control error is as follows:
java.net.SocketException:Software caused connection Abort:recv failed at Java. NET. Socketinputstream. Socketread0 (Native Method) at Java. NET. Socketinputstream. Read(Socketinputstream. Java: the) at Java. NET. Socketinputstream. Read(Socketinputstream. Java:122) at Sun. NiO. CS. Streamdecoder. Readbytes(Streamdecoder. Java:283) at Sun. NiO. CS. Streamdecoder. Implread(Streamdecoder. Java:325) at Sun. NiO. CS. Streamdecoder. Read(Streamdecoder. Java:177) at Java. IO. InputStreamReader. Read(InputStreamReader. Java:184) at Java. IO. BufferedReader. Fill(BufferedReader. Java:154) at Java. IO. BufferedReader. Read(BufferedReader. Java:175) at Org. Apache. Commons. NET. IO. Crlflinereader. ReadLine(Crlflinereader. Java: -) at Org. Apache. Commons. NET. FTP. FTP. __getreply (FTP. Java:314) at Org. Apache. Commons. NET. FTP. FTP. __getreply (FTP. Java:294) at Org. Apache. Commons. NET. FTP. FTP. SendCommand(FTP. Java:483) at Org. Apache. Commons. NET. FTP. FTP. SendCommand(FTP. Java:608) at Org. Apache. Commons. NET. FTP. FTP. Port(FTP. Java:932) at Org. Apache. Commons. NET. FTP. FtpClient. _opendataconnection_ (FtpClient. Java:812) at Org. Apache. Commons. NET. FTP. FtpClient. _storefile (FtpClient. Java:633) at Org. Apache. Commons. NET. FTP. FtpClient. __storefile (FtpClient. Java:624) at Org. Apache. Commons. NET. FTP. FtpClient. StoreFile(ftpclient. Java:1976) atcom. Taotao. Utils. Ftputil. UploadFile(Ftputil. Java: the) atcom. Taotao. Controller. Test. Ftptest. Testftputils(Ftptest. Java: the) at Sun. Reflect. Nativemethodaccessorimpl. Invoke0 (Native Method) at Sun. Reflect. Nativemethodaccessorimpl. Invoke(Nativemethodaccessorimpl. Java: $) at Sun. Reflect. Delegatingmethodaccessorimpl. Invoke(Delegatingmethodaccessorimpl. Java: +) at Java. Lang. Reflect. Method. Invoke(Method. Java:606) at Org. JUnit. Runners. Model. Frameworkmethod$. Runreflectivecall(Frameworkmethod. Java: -) at Org. JUnit. Internal. Runners. Model. Reflectivecallable. Run(reflectivecallable. Java: A) at Org. JUnit. Runners. Model. Frameworkmethod. invokeexplosively(Frameworkmethod. Java: -) at Org. JUnit. Internal. Runners. Statements. InvokeMethod. Evaluate(InvokeMethod. Java: -) at Org. JUnit. Runners. Parentrunner. Runleaf(Parentrunner. Java:325) at Org. JUnit. Runners. Blockjunit4ClassRunner. Runchild(Blockjunit4classrunner. Java: +) at Org. JUnit. Runners. Blockjunit4ClassRunner. Runchild(Blockjunit4classrunner. Java: $) at Org. JUnit. Runners. Parentrunner$. Run(Parentrunner. Java:290) at Org. JUnit. Runners. Parentrunner$. Schedule(Parentrunner. Java: in) at Org. JUnit. Runners. Parentrunner. Runchildren(Parentrunner. Java:288) at Org. JUnit. Runners. Parentrunner. Access$000 (Parentrunner. Java: -) at Org. JUnit. Runners. Parentrunner$. Evaluate(Parentrunner. Java:268) at Org. JUnit. Runners. Parentrunner. Run(Parentrunner. Java:363) at Org. Eclipse. JDT. Internal. JUnit4. Runner. JUnit4TestReference. Run(junit4testreference. Java: the) at Org. Eclipse. JDT. Internal. JUnit. Runner. Testexecution. Run(testexecution. Java: -) at Org. Eclipse. JDT. Internal. JUnit. Runner. Remotetestrunner. Runtests(Remotetestrunner. Java:459) at Org. Eclipse. JDT. Internal. JUnit. Runner. Remotetestrunner. Runtests(Remotetestrunner. Java:675) at Org. Eclipse. JDT. Internal. JUnit. Runner. Remotetestrunner. Run(Remotetestrunner. Java:382) at Org. Eclipse. JDT. Internal. JUnit. Runner. Remotetestrunner. Main(Remotetestrunner. Java:192)

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the error set-the use of Apache-nginx to build a picture server to complete the image upload function, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.