KickJava   Java API By Example, From Geeks To Geeks.

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


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 SftpTransfer 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 SftpConnection con = null;
17     private String JavaDoc type;
18     public Thread JavaDoc runner;
19     private Vector JavaDoc listeners;
20     private SshConnectionProperties props;
21     private String JavaDoc keyfile;
22
23     public SftpTransfer(SshConnectionProperties props, 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)
26     {
27         this.props = props;
28         this.localPath = localPath;
29         this.remotePath = remotePath;
30         this.file = file;
31         this.user = user;
32         this.pass = pass;
33         this.type = type;
34         this.listeners = listeners;
35         this.keyfile = keyfile;
36
37         prepare();
38     }
39
40     public void prepare()
41     {
42         runner = new Thread JavaDoc(this);
43         runner.setPriority(Thread.MIN_PRIORITY);
44         runner.start();
45     }
46
47     public void run()
48     {
49         con = new SftpConnection(props, keyfile);
50         con.setConnectionListeners(listeners);
51         con.login(user, pass);
52         con.setLocalPath(localPath);
53         con.chdir(remotePath);
54
55         if(type.equals(Transfer.DOWNLOAD))
56         {
57             con.download(file);
58         }
59         else if(type.equals(Transfer.UPLOAD))
60         {
61             con.upload(file);
62         }
63     }
64
65     public SftpConnection getSftpConnection()
66     {
67         return con;
68     }
69 }
70
Popular Tags