1 package net.sf.jftp.net; 2 3 import java.util.Vector ; 4 5 import com.sshtools.j2ssh.configuration.SshConnectionProperties; 6 7 8 public class SftpTransfer implements Runnable 9 { 10 private String host; 11 private String localPath; 12 private String remotePath; 13 private String file; 14 private String user; 15 private String pass; 16 private SftpConnection con = null; 17 private String type; 18 public Thread runner; 19 private Vector listeners; 20 private SshConnectionProperties props; 21 private String keyfile; 22 23 public SftpTransfer(SshConnectionProperties props, String localPath, String remotePath, 24 String file, String user, String pass, 25 Vector listeners, String type, String 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 (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 |