Connect to FTP Server Example
This program demonstrates connecting to an FTP server.
Problem Statement
Write a Java program that connects to an FTP server using Apache Commons Net.
Source Code
| 1 | import org.apache.commons.net.ftp.FTPClient; |
| 2 | public class FTPConnectExample { |
| 3 | public static void main(String[] args) { |
| 4 | System.out.println("Eduinq FTP Connect Example"); |
| 5 | FTPClient ftp=new FTPClient(); |
| 6 | try { |
| 7 | ftp.connect("ftp.eduinq.com"); |
| 8 | boolean login=ftp.login("user","password"); |
| 9 | System.out.println("Eduinq Login Success: "+login); |
| 10 | ftp.logout(); |
| 11 | ftp.disconnect(); |
| 12 | } catch(Exception e) { |
| 13 | System.out.println("Eduinq Exception: "+e.getMessage()); |
| 14 | } |
| 15 | } |
| 16 | } |
Program Output
Eduinq FTP Connect Example Eduinq Login Success: true
Explanation
Uses FTPClient to connect and authenticate. - Login credentials required for access. - Exception handling ensures safe operations. - In enterprise systems, FTP connection is used for file exchange. Conclusion: Shows connecting to FTP server.