JAVA basics: Implement FTP functions in JAVA programs

Source: Internet
Author: User
JAVA basics: Implement FTP functions in JAVA programs-general Linux technology-Linux programming and kernel information. For details, refer to the following section. In JAVA programming, you may encounter FTP programming. This article will demonstrate how to implement it.

This program is developed by JBUILDER2.0. To save space, I only list the three main parts. The FtpList part is used to display files on the FTP server (shown in the figure below ). The GetButton part uploads a file from the FTP server. The PutButton part uploads a file to the FTP server. Do not forget to introduce two library files (import sun.net. *, import sun.net. ftp. *) in the program .*). The following are the three JAVA source programs.

1) display files on the FTP server
CODE: void ftplist_actionreceivmed (ActionEvent e ){
String server = serverEdit. getText ();
// Enter the IP address of the FTP server
String user = userEdit. getText ();
// Username used to log on to the FTP server
String password = passwordEdit. getText ();
// Password of the username used to log on to the FTP server
String path = pathEdit. getText ();
// Path on the FTP server
Try {
FtpClient ftpClient = new FtpClient ();
// Create an FtpClient object
FtpClient. openServer (server );
// Connect to the FTP server
FtpClient. login (user, password );
// Log on to the FTP server
If (path. length ()! = 0) ftpClient. cd (path );
TelnetInputStream is = ftpClient. list ();
Int c;
While (c = is. read ())! =-1 ){
System. out. print (char) c );}
Is. close ();
FtpClient. closeServer (); // exit the FTP server
} Catch (IOException ex ){;}
}
Related Article

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.