Java ftpclient Problems

Source: Internet
Author: User

Java ftpclient problem (sun.net. FTP. ftpclient)

1 sun.net. FTP. ftpprotocolexception: Port: 501 port not allowed after epsv all, active mode off many FTP servers use the passive mode for transmission. You can use the ftpclient command. sendserver ("PASV. Do not use int reply = ftpclient. readserverresponse () later; otherwise, the problem persists.

 

2 java.net. socketexception: Connection Reset causes this problem because the client is closed before the download is complete. It can also be understood as follows: a circulation channel is established between the client and the server. When the channel is inbound and outbound, and the channel continues to enter at the end, you have shut down the outbound terminal, in this case, a Connection Reset exception is reported.

Of course, normally, after the stream enters and ends, how can we determine whether a large file has ended? Of course, you can use the command ftpclient. sendserver ("quit") to solve the problem.

/*

FTP remote command list user port RETR allo DELE site xmkd cdup feat pass PASV stor rest CWD stat RMD xcup opts Acct type appe RNFR xcwd help xrmd STOU auth rein stru smnt rnto list Noop PWD size pbsz quit mode syst Abor nlst mkd xpwd MDTM prot

*/

/*

Run commands on the server. If sendserver is used to execute remote commands (local FTP commands cannot be executed), add rn ftpclient to all FTP commands. sendserver ("xmkd/test/bbrn"); // execute the FTP command ftpclient on the server. readserverresponse must call namelist ("/test") after sendserver to obtain the xmkd directory in the file list under the specified directory, if a directory exists and the directory is created again, an error is returned. xrmd deletes the directory. DELE deletes the file.

*/

Ftpclient = new ftpclient ();

// Create the ftpclient object ftpclient. openserver (server );

// Connect to the FTP server

Ftpclient. login (user, password );

If (path. Length ()! = 0) ftpclient. Cd (PATH );

Ftpclient. Binary ();

// Ftpclient. sendserver ("PASV ");

// Int reply = ftpclient. readserverresponse ();

Telnetinputstream is = ftpclient. Get ("Smit. log ");

// Telnetinputstream is = ftpclient. List ();

// Telnetinputstream is = ftpclient. namelist (PATH );

Int C;

While (C = is. Read ())! =-1 ){

System. Out. Print (char) C );

}

Is. Close ();

// Ftpclient. closeserver ();

// Exit the FTP server

// Ftpclient. sendserver ("Get Smit. logrn ");

Int reply = ftpclient. readserverresponse ();

Ftpclient. sendserver ("quitrn ");

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.