package scp;


import org.apache.tools.ant.taskdefs.optional.ssh.*;
import junit.framework.TestCase;
import java.io.*;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;


public class ScpTest extends TestCase {

    private File tempDir;
    private String sshHostUri;
    private int port=22;
    private String knownHosts;   

    public ScpTest(String testname, String host, String file) {
        super(testname);
        this.sshHostUri=host;
        this.tempDir=new File(file);
    }

    public void Upload() throws IOException {
        Scp scp = createTask();
        FileSet fileset = new FileSet();
        fileset.setDir(tempDir);
        scp.addFileset(fileset);
        scp.setTodir(sshHostUri);
        scp.execute();
    }


    private Scp createTask() {
        Scp scp = new Scp();
        Project p = new Project();
        p.init();
        scp.setProject(p);
        if (knownHosts != null) {
            scp.setKnownhosts(knownHosts);
        } else {
            scp.setTrust(true);
        }
        scp.setPort(port);
        return scp;
    }
}
