In today's discussion we will came across 'How to establish connection with FTP
server in Java'. We are using 'apache commons-net' API that holds all necessary
classes to deal with FTP operations like, create connection , get list of all files on ftp , upload file to ftp , download files from ftp , create and delete a directory on ftp and delete a file on ftp.
In this particular blog we will
see an example of how to connect to ftp server in java, all steps included in
the process are:
1) Get a 'FtpClient' object from
'org.apache.commons.net.ftp.FTPClient' Class.
2) Use
'connect()' method of API to open a connection to the FTP Server, pass
ftp path or url as parameter to connect() method.
3)
Call login() method of API on ftpClient, and pass server
credentials as parameter. It returns 'true' if login is successful and false
otherwise.
4) Call logout() method of API on ftpClient to
logout from connected ftp server. It returns 'true' if logout is successful and
false otherwise.
5) Call disconnect() method of API on
ftpClient to end connection from connected ftp server. It returns 'true'
if disconnect is successful and false otherwise.
<dependencies> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> </dependencies>
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology