// // **************************** Security Warning! ************************ // This is a serious warning, and you need to pay attention to it. // // To work, this program needs you to put your ftp password into the // code as a String. This is only appropriate on an Intranet or when // the applet is on a page to which access is otherwise controlled. // // A malicious person could access the applet class file and easily // retrieve YOUR password. Then they would have access to your ftp // account. They could add, delete, or change files. They could even // change the password. That would be very bad for you. // // Giving away your password is frequently not allowed by the terms of // your account provider. Do NOT use this program unless you are // authorized to pass on your ftp password, and you are able to firewall // the ftp account or otherwise protect against intrusion. One thing // you could do is have a very small ftp area, and only allow existing // files to be appended (for example). // // Creating an applet with this program is like publishing your password // to anyone who can access the applet class file. // // If you still want to proceed, it is at your own risk. // **************************** Security Warning! ************************ // Instructions: // 1. This file contains the applet I/O class Linlyn, and // a sample applet, t, that uses it. // // 2. modify the literal strings in t.java // to use your server, username, passwd etc. // // 3. compile by typing // javac t.java // // 4. try running by: // appletviewer t.java // it will upload and retrieve a file for an applet // (The html to run it is in this file, so t.java not t.html is OK). // // 5. modify t.java to be your own applet // // While getting started, you might want to uncomment the // "debug" lines near the head of Linlyn.java; this will // produce output to help in your initial configuration. // // if this works for you, send a note to pvdl@afu.com, May 1998. /* This runs the Linlyn applet


*/ // a test applet to show the use of the Linlyn class // you don't have to embed the passwd in the code - you could // prompt for it. // import java.awt.*; // needed by the applet import java.applet.*; import java.io.*; // needed by Linlyn import java.net.*; import java.util.*; public class t extends Applet { public void init() { try { // upload to file // You must replace the strings with actual values to use. // e.g. Linlyn("microsoft.com","billg", "allmy$$$"); Linlyn u = new Linlyn("YOUR_SERVER", "USERNAME", "PASSWD"); u.upload("pub", "score.txt", "'Just Java 2' is a great Java book! \n" + "available quick and cheap from \n" + " http://www.amazon.com/exec/obidos/ASIN/0130105341/afuinc "); // add some more onto end of existing file Linlyn u2 = new Linlyn("YOUR_SERVER", "USERNAME", "PASSWD"); u2.append("pub", "score.txt", "append this info at ONCE", true); // download from file // You must replace the strings with actual values to use. Linlyn d = new Linlyn("YOUR_SERVER", "USERNAME", "PASSWD"); String s = d.download("pub", "score.txt"); // display file contents TextArea ta = new TextArea( s, 3, 40); add(ta); } catch(java.io.IOException ioe) {ioe.printStackTrace();} } } ////////////////////////////////////////// // split here for Linlyn.java // // At last! Java code to read/write files on the server from an applet! // This is the famous Linlyn code. // // Use: // compile this file, and have your applet call it as below. // // to upload a file: // Linlyn ftp = new Linlyn( , , ); // ftp.upload( , , ); // // to download a file: // Linlyn ftp = new Linlyn( , , ); // String contents = ftp.download( , ); // // the default is ASCII transfer, an overloaded method does bin. // // All parameters and return values are Strings. E.g. // Linlyn ftp = new Linlyn( "rtfm.mit.edu", "anonymous", "linden@" ); // String contents = ftp.download( // "/pub/usenet-by-group/comp.lang.java.programmer" // "Java_Programmers_FAQ" ); // // [the actual values above are not generally valid, substitute // your own server for your first attempt, see note 1.] // // Notes: // 1. Usual applet security rules apply: you can only get a file // from the server that served the applet. // 2. The applet server must also be an FTP server. This is NOT true // for some ISPs, such as best.com. They have separate FTP and // http machines. This code may work on such a setup if you put // the classfiles into the ftp area, and in the HTML file say: //