1 import net.sf.jftp.net.ConnectionHandler; 2 import net.sf.jftp.net.ConnectionListener; 3 import net.sf.jftp.net.DataConnection; 4 import net.sf.jftp.net.FtpConnection; 5 import net.sf.jftp.net.BasicConnection; 6 import net.sf.jftp.util.Log; 7 import net.sf.jftp.util.Logger; 8 import net.sf.jftp.config.Settings; 9 10 import java.io.*; 11 12 15 public class FtpUpload implements Logger, ConnectionListener 16 { 17 18 private boolean isThere = false; 19 20 private ConnectionHandler handler = new ConnectionHandler(); 21 22 public FtpUpload(String host, String dir, String file) 23 { 24 Log.setLogger(this); 25 26 FtpConnection con = new FtpConnection(host); 27 28 con.addConnectionListener(this); 29 30 con.setConnectionHandler(handler); 31 32 con.login("anonymous","no@no.no"); 33 34 while(!isThere) 35 { 36 try { Thread.sleep(10); } 37 catch(Exception ex) { ex.printStackTrace(); } 38 } 39 40 con.chdir(dir); 41 42 con.upload(file); 43 } 44 45 public static void main(String argv[]) 46 { 47 if(argv.length == 3) 48 { 49 FtpUpload f = new FtpUpload(argv[0], argv[2], argv[1]); 50 } 51 else 52 { 53 FtpUpload g = 54 new FtpUpload("upload.sourceforge.net", "/incoming", "test.txt"); 55 } 56 } 57 58 59 public void updateRemoteDirectory(BasicConnection con) 60 { 61 System.out.println("new path is: " + con.getPWD()); 62 } 63 64 public void connectionInitialized(BasicConnection con) 65 { 66 isThere = true; 67 } 68 69 public void updateProgress(String file, String type, long bytes) {} 70 71 public void connectionFailed(BasicConnection con, String why) {System.out.println("connection failed!");} 72 73 public void actionFinished(BasicConnection con) {} 74 75 public void debug(String msg) {System.out.println(msg);} 76 77 public void debugRaw(String msg) {System.out.print(msg);} 78 79 public void debug(String msg, Throwable throwable) {} 80 81 public void warn(String msg) {} 82 83 public void warn(String msg, Throwable throwable) {} 84 85 public void error(String msg) {} 86 87 public void error(String msg, Throwable throwable) {} 88 89 public void info(String msg) {} 90 91 public void info(String msg, Throwable throwable) {} 92 93 public void fatal(String msg) {} 94 95 public void fatal(String msg, Throwable throwable) {} 96 97 } 98 | Popular Tags |