Данный пример демонстрирует использование FTP сервиса прямо на страничке в виде Ява Апплета.
import java.net.*; import java.io.*; import java.util.*; class uftp { public static Socket s=null; public static DataInputStream dis; public static PrintStream ps; public static String gelen="-"; public static Socket s2=null; public static DataInputStream dis2; public static PrintStream ps2; public static ServerSocket ss=null; public static DataOutputStream out2 ; public static String [] str=new String [10]; public static String birinci=""; public static String ikinci=""; public static String [] cok=new String [5]; public static String ucuncu=""; public static OutputStream out; public static byte [] da; public uftp(String username,String pass,String host,byte [] da,String storfile) { try { s=new Socket(""+host,21); } catch(Exception e1) { System.out.println("e1:"+e1); } try { dis=new DataInputStream(s.getInputStream()); ps=new PrintStream(s.getOutputStream()); } catch(Exception e2) { System.out.println("e2:"+e2); } try { gelen=dis.readLine(); ps.println(username); gelen=dis.readLine(); ps.println(pass); gelen=dis.readLine(); ps.println("REST 100"); gelen=dis.readLine(); ps.println("PWD"); gelen=dis.readLine(); ps.println("TYPE I"); gelen=dis.readLine(); ps.println("PASV"); gelen=dis.readLine(); StringTokenizer st=new StringTokenizer(gelen,","); int ii=0; while(st.hasMoreTokens()) { str[ii]=st.nextToken(); ii++; } birinci=str[(ii-2)]; ucuncu=str[(ii-1)]; StringTokenizer st2=new StringTokenizer(ucuncu,")"); ii=0; while(st2.hasMoreTokens()) { cok[ii]=st2.nextToken(); ii++; } ikinci=cok[0]; int p=( ( ( Integer.valueOf(birinci).intValue() )*256 )+Integer.valueOf(ikinci).intValue() ); s2=new Socket(""+host,p); dis2=new DataInputStream(s2.getInputStream()); ps2=new PrintStream(s2.getOutputStream()); out = (s2.getOutputStream()); out.write(da); ps.println("STOR "+storfile); gelen=dis.readLine(); ps.println("QUIT"); out.close(); s2.close(); dis2.close(); ps2.close(); dis.close(); ps.close(); s.close(); } catch(Exception e12) { System.out.println("e12:"+e12); } } public static void main(String args[]) { File foofile; FileInputStream fis; byte [] da2; try { foofile=new File("blabla.txt"); fis=new FileInputStream(foofile); da2=new byte[fis.available()]; fis.read(da2); fis.close(); new uftp("USER blabla","PASS bla","ftp.blabla.com",da2,"blabla.txt"); } catch(Exception e14) { System.out.println("e14:"+e14); } } }