SlideShare a Scribd company logo
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




Apache FTP Server integration
Yoann Canal - twitter.com/y_canal
Sophiacom
Agenda

•   Apache FTP Server overview

•   First step: integration in your project

•   Authentication through WebObjects

•   FTPLet: what’s that?

•   Q&A
Preamble

•   The Apache project is not well documented :-(

•   You get almost nothing when you google “Apache FTP Server
    WebObjects”

•   FTP Server has been designed with Spring in mind


➡ This session will not show you a reusable framework but the
     goal is to give you our feedback with some piece of code
Apache FTP Server overview
FTP Server Overview

Except from project web page:

The Apache FtpServer is a 100% pure Java FTP server. It's designed to be a complete and
portable FTP server engine solution based on currently available open protocols. FtpServer
can be run standalone as a Windows service or Unix/Linux daemon, or embedded into a
Java application.We also provide support for integration within Spring applications and
provide our releases as OSGi bundles.
Documentation and download: http://mina.apache.org/ftpserver/
FTP Server Overview

•   Current release is 1.06 (posted on Jul 16, 2011)

•   Url to download:
    http://mina.apache.org/ftpserver/apache-ftpserver-106-
    release.html

•   No dependancies with other libraries
Basic Integration
Project Setup

•   Add the following libraries:
    • ftplet-api-1.0.6.jar
    • ftpserver-core-1.0.6.jar
    • mina-core-2.0.4.jar
•   Initialize an Apache FtpServer
    object in your application or a
    Framework Principal object
FTP Server Initialization

	   FtpServerFactory serverFactory = new FtpServerFactory();

	   // listen to a port > 1024
	   // This port is used when connecting to the FTP Server
	   // ex: ftp ftp://userName@localhost:1250
	   ListenerFactory listenerFactory = new ListenerFactory();
	   listenerFactory.setPort(1250);
	   Listener listener = listenerFactory.createListener();
	   serverFactory.addListener("default", listener);

	   FtpServer server = serverFactory.createServer();
	   try {
	        server.start();
	   } catch (FtpException e) {
	        e.printStackTrace();
	   }
Authentication through
    WebObjects
Authentication

•   You have 2 classes to create

    •   One implements User
        •At least must return the name and the home directory

    •   The other implements UserManager
        • check if the user is allowed to connect
        • create an authenticated User
Authentication

    public class FTPUser implements User {
	   private final String login;

	   public FTPUser(final String login) {
	   	    this.login = login;
	   }

	   @Override
	   public AuthorizationRequest authorize(final AuthorizationRequest authRequest) {
	   	    return authRequest;
	   }

	   @Override
	   public boolean getEnabled() {
	   	    return true;
	   }

	   @Override
	   public String getHomeDirectory() {
	   	    return "/tmp/FTP/" + login;
	   }

	   @Override
	   public int getMaxIdleTime() {
	   	    return 0;
	   }

	   @Override
	   public String getName() {
	   	    return this.login;
	   }
}
Authentication

    	
	   public class FTPUserManager implements UserManager {

	   	   @Override
	   	   public User authenticate(final Authentication inAuth) throws AuthenticationFailedException {
	   	   	 // inAuth is always an UsernamePasswordAuthentication
	   	   	 UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication)inAuth;
	   	   	 String login = upa.getUsername();
	   	   	 String password = upa.getPassword();

	   	   	   // check user existence and credentials in database
	   	   	   if(!EOUser.authenticate(login, password))
	   	   	   	 throw new AuthenticationFailedException();

	   	   	   return new FTPUser(login);
	   	   }

	   	   @Override
	   	   public User getUserByName(final String login) throws FtpException {
	   	   	 return new FTPUser(login);
	   	   }
	   }
Authentication


    	
	   FtpServerFactory serverFactory = new FtpServerFactory();

	   // listen to a port > 1024
	   ListenerFactory listenerFactory = new ListenerFactory();
	   listenerFactory.setPort(1252);
	   Listener listener = listenerFactory.createListener();
	   serverFactory.addListener("default", listener);

	   // set the user manager
	   serverFactory.setUserManager(new FTPUserManager());

	   FtpServer server = serverFactory.createServer();
FTPLet
FTPLet

•   Give an opportunity to override the default behavior of a FTP
    Server

•   You can redefine all commands like ls, get, put, delete, mkdir…

•   Example: insert data automatically from an uploaded file
FTPLet example

	   public class MyFTPLet extends DefaultFtplet {

	   	    @Override
	   	    public FtpletResult onLogin(final FtpSession session, final FtpRequest request) throws FtpException, IOException {
	   	    	   File userRoot = new File(session.getUser().getHomeDirectory());
	   	    	   userRoot.mkdirs();

	   	    	    return super.onLogin(session, request);
	         }

	         @Override
	   	    public FtpletResult onMkdirStart(final FtpSession session, final FtpRequest request) throws FtpException, IOException {
	   	    	    session.write(new DefaultFtpReply(FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "You can't create directories on this server."));
	   	    	    return FtpletResult.SKIP;
	   	    }

	   	    @Override
	   	    public FtpletResult onUploadEnd(final FtpSession session, final FtpRequest request) throws FtpException, IOException {
	    	        String userRoot = session.getUser().getHomeDirectory();
	   	    	   String currDir = session.getFileSystemView().getWorkingDirectory().getAbsolutePath();
	   	    	   String fileName = request.getArgument();

	    	        File f = new File(userRoot + currDir + fileName);
	   	    	    // do something fun with this file
	   	    }
	   }
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012




Q&A

More Related Content

PDF
2014-10-30 Taverna 3 status
PPT
香港六合彩 » SlideShare
PPT
Baocao Web Tech Java Mail
PDF
Lecture11 b
PDF
Flask Introduction - Python Meetup
PDF
Flask With Server-Sent Event
PPT
Learn flask in 90mins
PDF
Speech for Windows Phone 8
2014-10-30 Taverna 3 status
香港六合彩 » SlideShare
Baocao Web Tech Java Mail
Lecture11 b
Flask Introduction - Python Meetup
Flask With Server-Sent Event
Learn flask in 90mins
Speech for Windows Phone 8

What's hot (19)

PPT
Learn REST API with Python
PDF
Authoring CPAN modules
PDF
Python Google Cloud Function with CORS
PDF
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
PPTX
Powershell alias
PPTX
CCI2019 - I've got the Power! I've got the Shell!
PPTX
Input and output flow using http and java component
PPTX
Mule esb :Data Weave
ODP
Java 7 Features and Enhancements
PPSX
Sunil phani's take on windows powershell
PPTX
Flask – Python
PPTX
Python at Facebook
TXT
Easy install
PPT
Write book in markdown
PDF
InfiniFlux collector
PDF
PyCon 2005 PyBlosxom
PPTX
Groovy example in mule
PPTX
MuleSoft ESB scatter-gather and base64
PDF
Server Side? Swift
Learn REST API with Python
Authoring CPAN modules
Python Google Cloud Function with CORS
Infinum Android Talks #16 - Retrofit 2 by Kristijan Jurkovic
Powershell alias
CCI2019 - I've got the Power! I've got the Shell!
Input and output flow using http and java component
Mule esb :Data Weave
Java 7 Features and Enhancements
Sunil phani's take on windows powershell
Flask – Python
Python at Facebook
Easy install
Write book in markdown
InfiniFlux collector
PyCon 2005 PyBlosxom
Groovy example in mule
MuleSoft ESB scatter-gather and base64
Server Side? Swift
Ad

Similar to Apache FTP Server Integration (20)

PDF
Ftp servlet
PPT
Ftp tftp
PPTX
solar wind66657657777777544533335567.pptx
PPTX
Ftp: a slideshow on File transfer protocol
PPTX
An overview of ftp
PPTX
FTP(In_Linux).pptx
PPT
Ftp.75 to 76
PPTX
File transfer protocol (ftp) in application
DOCX
File transfer protocol
PPTX
BITM3730Week10.pptx
PPT
US07FFT-mod_ftp.ppt
PPT
US07FFT-mod_ftp.ppt
PPT
US07FFT-mod_ftp.ppt
PDF
File Transfer Protocol (FTP) in Computer Networks_ A Complete Guide.pdf
PDF
Ftp
PDF
Lecture 7 -_ftp,_tftp,_telnet_and_ssh
PPT
ftp.07f.ppt
PPTX
Introduction to File Transfer Protocol with commands in FTP
PPTX
File transfer protocol (ftp)
PDF
File server
Ftp servlet
Ftp tftp
solar wind66657657777777544533335567.pptx
Ftp: a slideshow on File transfer protocol
An overview of ftp
FTP(In_Linux).pptx
Ftp.75 to 76
File transfer protocol (ftp) in application
File transfer protocol
BITM3730Week10.pptx
US07FFT-mod_ftp.ppt
US07FFT-mod_ftp.ppt
US07FFT-mod_ftp.ppt
File Transfer Protocol (FTP) in Computer Networks_ A Complete Guide.pdf
Ftp
Lecture 7 -_ftp,_tftp,_telnet_and_ssh
ftp.07f.ppt
Introduction to File Transfer Protocol with commands in FTP
File transfer protocol (ftp)
File server
Ad

More from WO Community (20)

PDF
KAAccessControl
PDF
In memory OLAP engine
PDF
Using Nagios to monitor your WO systems
PDF
Build and deployment
PDF
High availability
PDF
Reenabling SOAP using ERJaxWS
PDF
Chaining the Beast - Testing Wonder Applications in the Real World
PDF
D2W Stateful Controllers
PDF
Deploying WO on Windows
PDF
Unit Testing with WOUnit
PDF
Life outside WO
PDF
Apache Cayenne for WO Devs
PDF
Advanced Apache Cayenne
PDF
Migrating existing Projects to Wonder
PDF
iOS for ERREST - alternative version
PDF
iOS for ERREST
PDF
"Framework Principal" pattern
PDF
Filtering data with D2W
PDF
PDF
Localizing your apps for multibyte languages
KAAccessControl
In memory OLAP engine
Using Nagios to monitor your WO systems
Build and deployment
High availability
Reenabling SOAP using ERJaxWS
Chaining the Beast - Testing Wonder Applications in the Real World
D2W Stateful Controllers
Deploying WO on Windows
Unit Testing with WOUnit
Life outside WO
Apache Cayenne for WO Devs
Advanced Apache Cayenne
Migrating existing Projects to Wonder
iOS for ERREST - alternative version
iOS for ERREST
"Framework Principal" pattern
Filtering data with D2W
Localizing your apps for multibyte languages

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
sap open course for s4hana steps from ECC to s4
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MIND Revenue Release Quarter 2 2025 Press Release
MYSQL Presentation for SQL database connectivity
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
sap open course for s4hana steps from ECC to s4
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”

Apache FTP Server Integration

  • 1. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 Apache FTP Server integration Yoann Canal - twitter.com/y_canal Sophiacom
  • 2. Agenda • Apache FTP Server overview • First step: integration in your project • Authentication through WebObjects • FTPLet: what’s that? • Q&A
  • 3. Preamble • The Apache project is not well documented :-( • You get almost nothing when you google “Apache FTP Server WebObjects” • FTP Server has been designed with Spring in mind ➡ This session will not show you a reusable framework but the goal is to give you our feedback with some piece of code
  • 4. Apache FTP Server overview
  • 5. FTP Server Overview Except from project web page: The Apache FtpServer is a 100% pure Java FTP server. It's designed to be a complete and portable FTP server engine solution based on currently available open protocols. FtpServer can be run standalone as a Windows service or Unix/Linux daemon, or embedded into a Java application.We also provide support for integration within Spring applications and provide our releases as OSGi bundles. Documentation and download: http://mina.apache.org/ftpserver/
  • 6. FTP Server Overview • Current release is 1.06 (posted on Jul 16, 2011) • Url to download: http://mina.apache.org/ftpserver/apache-ftpserver-106- release.html • No dependancies with other libraries
  • 8. Project Setup • Add the following libraries: • ftplet-api-1.0.6.jar • ftpserver-core-1.0.6.jar • mina-core-2.0.4.jar • Initialize an Apache FtpServer object in your application or a Framework Principal object
  • 9. FTP Server Initialization FtpServerFactory serverFactory = new FtpServerFactory(); // listen to a port > 1024 // This port is used when connecting to the FTP Server // ex: ftp ftp://userName@localhost:1250 ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.setPort(1250); Listener listener = listenerFactory.createListener(); serverFactory.addListener("default", listener); FtpServer server = serverFactory.createServer(); try { server.start(); } catch (FtpException e) { e.printStackTrace(); }
  • 11. Authentication • You have 2 classes to create • One implements User •At least must return the name and the home directory • The other implements UserManager • check if the user is allowed to connect • create an authenticated User
  • 12. Authentication public class FTPUser implements User { private final String login; public FTPUser(final String login) { this.login = login; } @Override public AuthorizationRequest authorize(final AuthorizationRequest authRequest) { return authRequest; } @Override public boolean getEnabled() { return true; } @Override public String getHomeDirectory() { return "/tmp/FTP/" + login; } @Override public int getMaxIdleTime() { return 0; } @Override public String getName() { return this.login; } }
  • 13. Authentication public class FTPUserManager implements UserManager { @Override public User authenticate(final Authentication inAuth) throws AuthenticationFailedException { // inAuth is always an UsernamePasswordAuthentication UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication)inAuth; String login = upa.getUsername(); String password = upa.getPassword(); // check user existence and credentials in database if(!EOUser.authenticate(login, password)) throw new AuthenticationFailedException(); return new FTPUser(login); } @Override public User getUserByName(final String login) throws FtpException { return new FTPUser(login); } }
  • 14. Authentication FtpServerFactory serverFactory = new FtpServerFactory(); // listen to a port > 1024 ListenerFactory listenerFactory = new ListenerFactory(); listenerFactory.setPort(1252); Listener listener = listenerFactory.createListener(); serverFactory.addListener("default", listener); // set the user manager serverFactory.setUserManager(new FTPUserManager()); FtpServer server = serverFactory.createServer();
  • 16. FTPLet • Give an opportunity to override the default behavior of a FTP Server • You can redefine all commands like ls, get, put, delete, mkdir… • Example: insert data automatically from an uploaded file
  • 17. FTPLet example public class MyFTPLet extends DefaultFtplet { @Override public FtpletResult onLogin(final FtpSession session, final FtpRequest request) throws FtpException, IOException { File userRoot = new File(session.getUser().getHomeDirectory()); userRoot.mkdirs(); return super.onLogin(session, request); } @Override public FtpletResult onMkdirStart(final FtpSession session, final FtpRequest request) throws FtpException, IOException { session.write(new DefaultFtpReply(FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "You can't create directories on this server.")); return FtpletResult.SKIP; } @Override public FtpletResult onUploadEnd(final FtpSession session, final FtpRequest request) throws FtpException, IOException { String userRoot = session.getUser().getHomeDirectory(); String currDir = session.getFileSystemView().getWorkingDirectory().getAbsolutePath(); String fileName = request.getArgument(); File f = new File(userRoot + currDir + fileName); // do something fun with this file } }
  • 18. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 Q&A