Your SlideShare is downloading. ×
0
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Apache FTP Server Integration
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Apache FTP Server Integration

3,969

Published on

See how you can use the FTP server from the Apache Foundation with your WebObjects applications.

See how you can use the FTP server from the Apache Foundation with your WebObjects applications.

Published in: Technology
2 Comments
0 Likes
Statistics
Notes
  • Thanks!
    Nice presentation and very direct.
    This project miss more samples like this.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Short, crisp. The code examples in the slide helped me for kickoff.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
3,969
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
54
Comments
2
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012Apache FTP Server integrationYoann Canal - twitter.com/y_canalSophiacom
  • 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 OverviewExcept from project web page:The Apache FtpServer is a 100% pure Java FTP server. Its designed to be a complete andportable FTP server engine solution based on currently available open protocols. FtpServercan be run standalone as a Windows service or Unix/Linux daemon, or embedded into aJava application.We also provide support for integration within Spring applications andprovide 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
  • 7. Basic Integration
  • 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(); }
  • 10. Authentication through WebObjects
  • 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();
  • 15. FTPLet
  • 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 cant 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 2012Q&A

×