Secure FTP JAVA Style BY RICH HELTON (SUN CERTIFIED (SC) JAVA PROGRAMMER, SC JAVA DEVELOPER, SC ENTERPRISE ARCHITECT) Janu...
Secure Java FTP (Java Style)
JFtp– Java Network Browser <ul><li>The program can be found at  http://j-ftp.sourceforge.net/   </li></ul><ul><li>The sour...
Benefits of JFtp <ul><li>Can run the Java code from the browser through “Web Start”. </li></ul><ul><li>Can download the JA...
To Launch or Download <ul><li>JFtp can be run directly from the browser or downloaded.  </li></ul>
To Launch <ul><li>Clicking on “Launch via Java Web Start” will launch the JFtp from the browser.  </li></ul><ul><li>Java m...
To Launch <ul><li>After clicking the “Run” button.  </li></ul><ul><li>JFtp Starts: </li></ul>
To Launch <ul><li>Clicking on File->Connect to SFTP Server….. </li></ul><ul><li>SFTP Configuration Starts: </li></ul>
Matching <ul><li>When configuring SFTP, the ports, encryption, and authentication must match the server configuration for ...
Testing <ul><li>One method to test locally is to pull down OpenSSH on a test machine. </li></ul><ul><li>OpenSSH can be fou...
Testing <ul><li>Let’s connect through SFTP: </li></ul><ul><li>If Successful, the log window will tell you: </li></ul>
Testing SSH <ul><li>Let’s connect SSH through Tools->SSH Shell…: </li></ul><ul><li>If Successful, the SSH Shell will appea...
JAR File <ul><li>Instead of running from the “Web Start”, a JAR file can be used to run it using the “java –jar jtp.jar”  ...
Compiling Java
Compiling at the JFtp Code <ul><li>The source code can be found at  http://sourceforge.net/projects/j-ftp/files/ . </li></...
ANT <ul><li>Ant is a Java library and command-line tool. Ant's mission is to drive processes described in build files as t...
Building <ul><li>After installing Ant, run it in the build.xml directory: </li></ul>
Running <ul><li>The build will create a jtfp.jar file in the builds/jars directory. </li></ul><ul><li>This file can be run...
Editing JFTP
Looking at the JFtp Code <ul><li>The review Java Code, I usually use Jedit, because it is a simpler editor, found at  http...
Looking at the JFtp Code <ul><li>Jedit on JFtp.java: </li></ul>
Looking at the JFtp Code <ul><li>To get UML diagrams of the code, ArgoUML can be used to parse the code to display the dia...
UML <ul><li>The Unified Modeling Language (UML) is used to visualize the software and how it works in a standardized bluep...
ArgoUML
Javadocs <ul><li>Javadocs is a document generating tool that is part of Java that generates HTML files describing the Java...
Free Samples, as always <ul><li>JFtp provides free sample code if you don’t want to use the GUI. </li></ul><ul><li>Under t...
Compiling FtpDownload <ul><li>Make sure that the jftp.jar is in the classpath and compile the FtpDownload.java. </li></ul>
JFtp Libraries
JFtp makes use of 2 different Java Libraries <ul><li>JFtp uses a library for Jcraft’s “jsch” library, which is their Java ...
JSch <ul><li>The JSch package is found at  http://www.jcraft.com/jsch/ </li></ul><ul><li>Otherwise the standard j2ssh libr...
JSch <ul><li>The JSch package is found at  http://www.jcraft.com/jsch/ </li></ul><ul><li>Otherwise the standard j2ssh libr...
Sftp2Connection Class <ul><li>One of the wrapper classes that uses the Jsch  library is the Sftp2Connection class. </li></...
Sftp2Connection upload snippet public static void main(String[] args) { String  username  = &quot;RichH&quot;; String  pas...
Sftp2Connection Upload snippet <ul><li>The code snippet will create a secure connection for the Sftp2Connection class. </l...
Sftp2Connection Upload snippet <ul><li>Running through JFtp manually, you can observe if the file is uploaded: </li></ul>
Conclusion
There are many Open Source Solutions <ul><li>Users are no longer dependent on the survival of the software vendor. </li></...
Upcoming SlideShare
Loading in …5
×

Secure Ftp Java Style Rev004

1,859 views
1,774 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,859
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Secure Ftp Java Style Rev004

  1. 1. Secure FTP JAVA Style BY RICH HELTON (SUN CERTIFIED (SC) JAVA PROGRAMMER, SC JAVA DEVELOPER, SC ENTERPRISE ARCHITECT) January 2010
  2. 2. Secure Java FTP (Java Style)
  3. 3. JFtp– Java Network Browser <ul><li>The program can be found at http://j-ftp.sourceforge.net/ </li></ul><ul><li>The source code can be found at http://sourceforge.net/projects/j-ftp/files/ . </li></ul>
  4. 4. Benefits of JFtp <ul><li>Can run the Java code from the browser through “Web Start”. </li></ul><ul><li>Can download the JAR file and run it locally. </li></ul><ul><li>Cross Platform. Runs easily on Mac OSX, Linux, Windows, etc. </li></ul><ul><li>Runs multiple protocols, SFTP, SMB, NFS, HTTP, and various transfer protocols. </li></ul><ul><li>Open Source so the code can be used to execute batch jobs. </li></ul><ul><li>Free to use. </li></ul>
  5. 5. To Launch or Download <ul><li>JFtp can be run directly from the browser or downloaded. </li></ul>
  6. 6. To Launch <ul><li>Clicking on “Launch via Java Web Start” will launch the JFtp from the browser. </li></ul><ul><li>Java must be able to run from the local Browser. </li></ul><ul><li>If so a Security Warning will pop up: </li></ul>
  7. 7. To Launch <ul><li>After clicking the “Run” button. </li></ul><ul><li>JFtp Starts: </li></ul>
  8. 8. To Launch <ul><li>Clicking on File->Connect to SFTP Server….. </li></ul><ul><li>SFTP Configuration Starts: </li></ul>
  9. 9. Matching <ul><li>When configuring SFTP, the ports, encryption, and authentication must match the server configuration for handshaking. </li></ul><ul><li>The source for the dialog box can be found at http://kickjava.com/src/net/sf/jftp/gui/hostchooser/SftpHostChooser.java.htm </li></ul>
  10. 10. Testing <ul><li>One method to test locally is to pull down OpenSSH on a test machine. </li></ul><ul><li>OpenSSH can be found at http://www.openssh.com/ . </li></ul><ul><li>Using OpenSSH, users and groups can be created using: </li></ul><ul><li>C:Program FilesOpenSSHin>mkpasswd -l -u RichH >> ..etcpasswd </li></ul><ul><li>C:Program FilesOpenSSHin>mkgroup -l >> ..etcgroup </li></ul><ul><li>Starting open SSH is done with: </li></ul><ul><li>Verify it is started: </li></ul>
  11. 11. Testing <ul><li>Let’s connect through SFTP: </li></ul><ul><li>If Successful, the log window will tell you: </li></ul>
  12. 12. Testing SSH <ul><li>Let’s connect SSH through Tools->SSH Shell…: </li></ul><ul><li>If Successful, the SSH Shell will appear: </li></ul>
  13. 13. JAR File <ul><li>Instead of running from the “Web Start”, a JAR file can be used to run it using the “java –jar jtp.jar” command. </li></ul><ul><li>If Java is configured correctly, the JFtp will run in a Java Console that works like the “Web Start” version. </li></ul><ul><li>Some information about the GUI may be displayed: </li></ul>
  14. 14. Compiling Java
  15. 15. Compiling at the JFtp Code <ul><li>The source code can be found at http://sourceforge.net/projects/j-ftp/files/ . </li></ul><ul><li>Unzip the source, cd to j-ftp and ensure that the build.xml file is present: </li></ul><ul><li>Build.xml is the build file, similar to a “make” file for “C”, that Apache Ant will use to build and deploy the files. </li></ul>
  16. 16. ANT <ul><li>Ant is a Java library and command-line tool. Ant's mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. </li></ul><ul><li>It can be found http://ant.apache.org/ </li></ul>
  17. 17. Building <ul><li>After installing Ant, run it in the build.xml directory: </li></ul>
  18. 18. Running <ul><li>The build will create a jtfp.jar file in the builds/jars directory. </li></ul><ul><li>This file can be run with the “java –jar jftp.jar” command. </li></ul>
  19. 19. Editing JFTP
  20. 20. Looking at the JFtp Code <ul><li>The review Java Code, I usually use Jedit, because it is a simpler editor, found at http://www.jedit.org/ . </li></ul><ul><li>Eclipse is also one of the most Java Editor, found at http://www.eclipse.org/ . More information can be found at http://en.wikipedia.org/wiki/Eclipse_ide . </li></ul><ul><li>These editors are Open Source with any plugins for coding. </li></ul><ul><li>The main file will be found at “srcjava etsfjftpJFtp.java”. </li></ul><ul><li>Notice that the “package” name is “net.sf.jftp” which will define where the file has to live as well, as will as where the files will be placed in the JAR. </li></ul>
  21. 21. Looking at the JFtp Code <ul><li>Jedit on JFtp.java: </li></ul>
  22. 22. Looking at the JFtp Code <ul><li>To get UML diagrams of the code, ArgoUML can be used to parse the code to display the diagrams. </li></ul><ul><li>ArgoUML is an Open Source UML Modeler found at http://argouml.tigris.org/ . </li></ul>
  23. 23. UML <ul><li>The Unified Modeling Language (UML) is used to visualize the software and how it works in a standardized blueprint. An example Use case: </li></ul>
  24. 24. ArgoUML
  25. 25. Javadocs <ul><li>Javadocs is a document generating tool that is part of Java that generates HTML files describing the Java code. Referenced from http://en.wikipedia.org/wiki/Javadocs . </li></ul><ul><li>This is a way to self document the code. Inserting macros and comments in the code will create an HTML browse able view of the code: </li></ul>
  26. 26. Free Samples, as always <ul><li>JFtp provides free sample code if you don’t want to use the GUI. </li></ul><ul><li>Under the doc directory, FTPDownload.java provides a download examples, and FTPUpload.java provides a upload example. </li></ul><ul><li>The “Web Start” code can also be found in this directory in the code “jftp.jnlp” </li></ul><ul><li>Information on the Java Network Launching Protocol can be found at http://en.wikipedia.org/wiki/.jnlp . </li></ul>
  27. 27. Compiling FtpDownload <ul><li>Make sure that the jftp.jar is in the classpath and compile the FtpDownload.java. </li></ul>
  28. 28. JFtp Libraries
  29. 29. JFtp makes use of 2 different Java Libraries <ul><li>JFtp uses a library for Jcraft’s “jsch” library, which is their Java Secure Shell, when the “Use JSch instead of j2ssh” is selected: </li></ul>
  30. 30. JSch <ul><li>The JSch package is found at http://www.jcraft.com/jsch/ </li></ul><ul><li>Otherwise the standard j2ssh library is used found at http://sourceforge.net/projects/sshtools/ . </li></ul><ul><li>Both libraries support the Secure Copy Protocol (SCP) for copying files through SSH. </li></ul><ul><li>JFtp creates wrappers in its net.sf.jtp.net.wrappers for use of such classes as SftpConnection, NfsConnection, HttpTransfer, Sftp2Connection, etc. that does the connection, downloading, uploading, change directory, remove directory and other work. </li></ul>
  31. 31. JSch <ul><li>The JSch package is found at http://www.jcraft.com/jsch/ </li></ul><ul><li>Otherwise the standard j2ssh library is used found at http://sourceforge.net/projects/sshtools/ . </li></ul><ul><li>Both libraries support the Secure Copy Protocol (SCP) for copying files through SSH. </li></ul><ul><li>JFtp creates wrappers in its net.sf.jtp.net.wrappers for use of such classes as SftpConnection, NfsConnection, HttpTransfer, Sftp2Connection, etc. that does the connection, downloading, uploading, change directory, remove directory and other work. </li></ul>
  32. 32. Sftp2Connection Class <ul><li>One of the wrapper classes that uses the Jsch library is the Sftp2Connection class. </li></ul><ul><li>This class has functionality for login, setLocalPath, upload, download, and more. </li></ul>
  33. 33. Sftp2Connection upload snippet public static void main(String[] args) { String username = &quot;RichH&quot;; String password = ”password&quot;; Sftp2Connection conn = new Sftp2Connection(&quot;localhost&quot;, &quot;&quot;+22, null); conn.login(username,password); System.out.println(&quot;PWD:&quot; +conn.getPWD()); System.out.println(&quot;Local Path:&quot;+conn.getLocalPath()); conn.setLocalPath(&quot;/jars&quot;); System.out.println(&quot;Local Path:&quot;+conn.getLocalPath()); conn.upload(&quot;jftp.jar&quot;); conn.disconnect(); }
  34. 34. Sftp2Connection Upload snippet <ul><li>The code snippet will create a secure connection for the Sftp2Connection class. </li></ul><ul><li>Then the login( ) function will authenticate using the username and password. </li></ul><ul><li>The Local directory will be the root directory as well as the remote directory, so the local directory is changed to “C:jars”. </li></ul><ul><li>This directory contains “C:jarsjftp.jar” that is uploaded with the upload ( ) function. </li></ul><ul><li>If there is any error along the way, an exception will happen pointing at the stack where the error code appeared. </li></ul>
  35. 35. Sftp2Connection Upload snippet <ul><li>Running through JFtp manually, you can observe if the file is uploaded: </li></ul>
  36. 36. Conclusion
  37. 37. There are many Open Source Solutions <ul><li>Users are no longer dependent on the survival of the software vendor. </li></ul><ul><li>Users can continue to develop and change the core of the acquired software. </li></ul><ul><li>Users can benefit from successful developments by others who have used or developed the software. </li></ul><ul><li>Open standards, such as XML are used for data exchange. The standards are open and not proprietary. </li></ul>

×