KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > net > Sftp2Transfer


1 package net.sf.jftp.net;
2
3 import java.util.Vector JavaDoc;
4
5 import com.sshtools.j2ssh.configuration.SshConnectionProperties;
6
7
8 public class Sftp2Transfer implements Runnable JavaDoc
9 {
10     private String JavaDoc host;
11     private String JavaDoc localPath;
12     private String JavaDoc remotePath;
13     private String JavaDoc file;
14     private String JavaDoc user;
15     private String JavaDoc pass;
16     private Sftp2Connection con = null;
17     private String JavaDoc type;
18     public Thread JavaDoc runner;
19     private Vector JavaDoc listeners;
20     private String JavaDoc keyfile;
21     private String JavaDoc port;
22     
23     public Sftp2Transfer(String JavaDoc localPath, String JavaDoc remotePath,
24                         String JavaDoc file, String JavaDoc user, String JavaDoc pass,
25                         Vector JavaDoc listeners, String JavaDoc type, String JavaDoc keyfile, String JavaDoc host, String JavaDoc port)
26     {
27         this.localPath = localPath;
28         this.remotePath = remotePath;
29         this.file = file;
30         this.user = user;
31         this.pass = pass;
32         this.type = type;
33         this.listeners = listeners;
34         this.keyfile = keyfile;
35         this.host = host;
36         this.port = port;
37
38         prepare();
39     }
40
41     public void prepare()
42     {
43         runner = new Thread JavaDoc(this);
44         runner.setPriority(Thread.MIN_PRIORITY);
45         runner.start();
46     }
47
48     public void run()
49     {
50         con = new Sftp2Connection(host, port, keyfile);
51         con.setConnectionListeners(listeners);
52         con.login(user, pass);
53         con.setLocalPath(localPath);
54         con.chdir(remotePath);
55
56         if(type.equals(Transfer.DOWNLOAD))
57         {
58             con.download(file);
59         }
60         else if(type.equals(Transfer.UPLOAD))
61         {
62             con.upload(file);
63         }
64     }
65
66     public Sftp2Connection getSftpConnection()
67     {
68         return con;
69     }
70 }
71
Popular Tags