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 ){;} } |