📄 gsiftp.java
字号:
import com.jscape.inet.ssh.*; import com.jscape.inet.ssh.util.SshParameters;import java.io.*; public class GSIFTP implements SshListener { // state of SSH connection private boolean connected = false; /** * Creates a new SshExample instance. * @return * */ public GSIFTP(String hostname,String password,String source,String hostdest,String dest,String userproxy,String passproxy) { Ssh ssh = null; try { String cmd = "whoami"; Runtime run = Runtime.getRuntime(); Process pr = run.exec(cmd); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); String userlog = ""; userlog=buf.readLine(); // create new Ssh instance SshParameters params = new SshParameters(hostname,userlog,password); ssh = new Ssh(params); // register to capture events ssh.addSshListener(this); System.out.println("Connecting please wait..."); // connect ssh.connect(); // get output stream for writing data to SSH server OutputStream out = ssh.getOutputStream(); // holds line entered at console String line = null; // read data from console if (connected) { String tam = "myproxy-logon -s ca -l "+userproxy+"\n"; out.write(tam.getBytes()); out.flush(); Thread.sleep(500); tam = passproxy+"\n"; out.write(tam.getBytes()); out.flush(); Thread.sleep(500); tam = "globus-url-copy gsiftp://"+hostname+source+" gsiftp://"+hostdest+dest+"\n"; out.write(tam.getBytes()); out.flush(); Thread.sleep(500); out.close(); } } catch (Exception e) { e.printStackTrace(); } finally { try { if(connected) { ssh.disconnect(); } } catch(Exception e) { } } } /** * Captures SshConnectedEvent */ public void connected(SshConnectedEvent ev) { System.out.println("Connected: " + ev.getHost()); connected = true; } /** * Captures SshDataReceivedEvent */ public void dataReceived(SshDataReceivedEvent ev) { // send data received to console System.out.print(ev.getData()); } /** * Captures SshDisconnectedEvent */ public void disconnected(SshDisconnectedEvent ev) { System.out.println("Disconnected: " + ev.getHost() + ". Press Enter to exit"); connected = false; } public static void main (String t[]) throws InterruptedException, IOException { GSIFTP tam=new GSIFTP("ca.cit.ctu.edu.vn","123456","/etc/group","alpha.cit.ctu.edu.vn","/tmp/","globus","123456"); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -