internal static PortWatcher getPort(Session session, String address, int lport) { InetAddress addr; try { addr=InetAddress.getByName(address); } catch(Exception uhe) { throw new JSchException("PortForwardingL: invalid address "+address+" specified."); } lock(pool) { for(int i=0; i<pool.size(); i++) { PortWatcher p=(PortWatcher)(pool.elementAt(i)); if(p.session==session && p.lport==lport) { if(p.boundaddress.isAnyLocalAddress() || p.boundaddress.equals(addr)) return p; } } return null; } }
internal static PortWatcher getPort(Session session, String address, int lport) { InetAddress addr; try { addr = InetAddress.getByName(address); } catch (Exception uhe) { throw new JSchException("PortForwardingL: invalid address " + address + " specified."); } lock (pool) { for (int i = 0; i < pool.size(); i++) { PortWatcher p = (PortWatcher)(pool.elementAt(i)); if (p.session == session && p.lport == lport) { if (p.boundaddress.isAnyLocalAddress() || p.boundaddress.equals(addr)) { return(p); } } } return(null); } }
public string DownloadFile(string fileUrl, string saveFilaFullName, bool overwrite = false) { FileInfo file = new FileInfo(saveFilaFullName); string localFullFileName = saveFilaFullName; int i = 1; if (!overwrite) { do { if (file.Exists) { localFullFileName = saveFilaFullName.Remove(saveFilaFullName.LastIndexOf(".")) + "_" + i.ToString() + file.Extension; } file = new FileInfo(localFullFileName); i++; } while (file.Exists); } if (!file.Directory.Exists) { file.Directory.Create(); } Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(fileUrl); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localFullFileName); sftp.get(src, dst); return(localFullFileName); }
internal static void delPort(Session session, String address, int lport) { PortWatcher pw = getPort(session, address, lport); if (pw == null) { throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " is not registered."); } pw.delete(); pool.removeElement(pw); }
internal static PortWatcher addPort(Session session, String address, int lport, String host, int rport, ServerSocketFactory ssf) { if (getPort(session, address, lport) != null) { throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " is already registered."); } PortWatcher pw = new PortWatcher(session, address, lport, host, rport, ssf); pool.addElement(pw); return(pw); }
public bool MakeDir(string remotePath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); m_sftp.mkdir(src); return(true); } catch { return(false); } }
public bool Rename(string oldPath, string newPath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(oldPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(newPath); m_sftp.rename(src, dst); return(true); } catch { return(false); } }
//SFTP获取文件 public bool Get(string remotePath, string localPath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); m_sftp.get(src, dst); return(true); } catch { return(false); } }
/// <summary> /// SFTP获取文件 /// </summary> /// <param name="remotePath"></param> /// <param name="localPath"></param> /// <returns></returns> public bool Get(string remotePath, string localPath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); m_sftp.get(src, dst); SFTP_Message = "获取文件成功"; return(true); } catch (Exception ex) { SFTP_Message = "获取文件失败,异常:" + ex.Message; return(false); } }
//--------------------------------------------------------------------- public string Put(string localPath, string remotePath) { string error = ""; try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); } catch (Exception ex) { error = ex.Message; } return(error); }
/// <summary> /// SFTP 上传文件 /// </summary> /// <param name="localPath"></param> /// <param name="remotePath"></param> /// <returns></returns> public bool Put(string localPath, string remotePath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); SFTP_Message = "上传成功"; return(true); } catch (Exception ex) { SFTP_Message = "上传失败,异常:" + ex.Message; this.Disconnect(); return(false); } }
//SFTP获取文件 public bool Get(string remotePath, string localPath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); m_sftp.get(src, dst); return(true); } catch (Exception io) { UnityEngine.Debug.Log(io.StackTrace); UnityEngine.Debug.Log(io.Data); UnityEngine.Debug.Log(io.Message); return(false); } }
/// <summary> /// SFTP获取文件 /// </summary> /// <param name="remotePath">sftp远程文件地址</param> /// <param name="localPath">本地文件存放路径</param> public bool Get(string remotePath, string localPath) { try { if (this.Connected) { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); m_sftp.get(src, dst); return(true); } } catch (Exception ex) { throw ex; } return(false); }
/// <summary> /// 移动SFTP文件 /// </summary> /// <param name="currentFilename">sftp远程文件地址</param> /// <param name="newDirectory">sftp移动至文件地址</param> public bool Move(string currentFilename, string newDirectory) { try { if (this.Connected) { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(currentFilename); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(newDirectory); m_sftp.rename(src, dst); return(true); } } catch (Exception ex) { throw ex; } return(false); }
//SFTP存放文件 public bool Upload(string localPath, string remotePath) { try { Connect(); if (this.Connected) { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); return(true); } } catch (Exception ex) { UnityEngine.Debug.Log("SFTP上传文件错误!" + ex.ToString()); return(false); } return(false); }
internal static String[] getPortForwarding(Session session) { java.util.Vector foo = new java.util.Vector(); lock (pool) { for (int i = 0; i < pool.size(); i++) { PortWatcher p = (PortWatcher)(pool.elementAt(i)); if (p.session == session) { foo.addElement(p.lport + ":" + p.host + ":" + p.rport); } } } String[] bar = new String[foo.size()]; for (int i = 0; i < foo.size(); i++) { bar[i] = (String)(foo.elementAt(i)); } return(bar); }
internal static String[] getPortForwarding(Session session) { java.util.Vector foo=new java.util.Vector(); lock(pool) { for(int i=0; i<pool.size(); i++) { PortWatcher p=(PortWatcher)(pool.elementAt(i)); if(p.session==session) { foo.addElement(p.lport+":"+p.host+":"+p.rport); } } } String[] bar=new String[foo.size()]; for(int i=0; i<foo.size(); i++) { bar[i]=(String)(foo.elementAt(i)); } return bar; }
//SFTP存放文件 public bool Put(string localPath, string remotePath) { try { Connect(); if (this.Connected) { m_sftp.cd("./../../app/");//进入文件存放目录 Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); return true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } return false; }
//SFTP存放文件 public bool Put(string localPath, string remotePath) { try { Connect(); if (this.Connected) { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); return(true); } } catch (Exception ex) { Console.WriteLine("SFTP上传文件错误!" + ex.ToString()); //Logger.error("SFTP上传文件错误!" + ex.ToString()); return(false); } return(false); }
internal PortWatcher(Session session, String address, int lport, String host, int rport, ServerSocketFactory factory) { this.session = session; this.lport = lport; this.host = host; this.rport = rport; try { boundaddress = InetAddress.getByName(address); ss = (factory == null) ? new ServerSocket(lport, 0, boundaddress) : factory.createServerSocket(lport, 0, boundaddress); } catch (Exception e) { Console.WriteLine(e); throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " cannot be bound."); } }
//SFTP下载文件 public bool DownloadFile(string remotePath, string localPath) { try { if (remotePath.EndsWith("/") || localPath.EndsWith("/")) { return(false); } Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); string localfolder = localPath.Substring(0, localPath.LastIndexOf("/")); DirectoryInfo dir = new DirectoryInfo(localfolder); if (!dir.Exists) { dir.Create(); } m_sftp.get(src, dst); return(true); } catch (Exception ex) { return(false); } }
//新建目录 public bool Mkdir(string path) { try { string root = "/"; string[] folders = path.Split('/'); foreach (string folder in folders) { if (folder.Length > 0 && (!folder.Equals("/"))) { Tamir.SharpSsh.java.String dir = new Tamir.SharpSsh.java.String(root + folder); bool isExists = false; SftpATTRS attrs; try { attrs = m_sftp.stat(dir); isExists = true; } catch (Exception e) { isExists = false; } if (isExists == false) { m_sftp.mkdir(dir); } root += folder + "/"; } } return(true); } catch { return(false); } }
//SFTP上传文件 public bool UploadFile(string localPath, string remotePath) { try { if (remotePath.EndsWith("/") || localPath.EndsWith("/")) { return(false); } Connect(); if (this.Connected) { //m_sftp.cd("./../../app/");//进入文件存放目录 Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); string remotefolder = remotePath.Substring(0, remotePath.LastIndexOf("/")); SftpATTRS attrs; try { attrs = m_sftp.stat(remotefolder); } catch (Exception e) { Mkdir(remotefolder); } m_sftp.put(src, dst); return(true); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); return(false); } return(false); }
/* void dump(byte[] foo){ for(int i=0; i<foo.length; i++){ if((foo[i]&0xf0)==0)System.out.print("0"); System.out.print(Integer.toHexString(foo[i]&0xff)); if(i%16==15){System.out.println(""); continue;} if(i%2==1)System.out.print(" "); } } */ internal static Tamir.SharpSsh.java.String[] guess(byte[]I_S, byte[]I_C) { //System.out.println("guess: "); Tamir.SharpSsh.java.String[] guess=new Tamir.SharpSsh.java.String[PROPOSAL_MAX]; Buffer sb=new Buffer(I_S); sb.setOffSet(17); Buffer cb=new Buffer(I_C); cb.setOffSet(17); for(int i=0; i<PROPOSAL_MAX; i++) { byte[] sp=sb.getString(); // server proposal byte[] cp=cb.getString(); // client proposal //System.out.println("server-proposal: |"+new String(sp)+"|"); //System.out.println("client-proposal: |"+new String(cp)+"|"); int j=0; int k=0; //System.out.println(new String(cp)); //loop(using BREAK instead): while(j<cp.Length) { while(j<cp.Length && cp[j]!=',')j++; if(k==j) return null; String algorithm=Util.getString(cp, k, j-k); //System.out.println("algorithm: "+algorithm); int l=0; int m=0; while(l<sp.Length) { while(l<sp.Length && sp[l]!=',')l++; if(m==l) return null; //System.out.println(" "+new String(sp, m, l-m)); if(algorithm.Equals(Util.getString(sp, m, l-m))) { guess[i]=algorithm; //System.out.println(" "+algorithm); goto BREAK; } l++; m=l; } j++; k=j; } BREAK: if(j==0) { guess[i]=""; } else if(guess[i]==null) { //System.out.println(" fail"); return null; } } // for(int i=0; i<PROPOSAL_MAX; i++){ // System.out.println("guess: ["+guess[i]+"]"); // } return guess; }
public StringBuffer append(Tamir.SharpSsh.java.String s) { return(append(s.ToString())); }
public StringBuffer(Tamir.SharpSsh.java.String s) : this(s.ToString()) { }
//SFTP存放文件 public bool Put(string localPath, string remotePath) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(src, dst); return true; } catch { return false; } }
public void setPortForwardingL(String boundaddress, int lport, String host, int rport, ServerSocketFactory ssf) { PortWatcher pw=PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf); Thread tmp=new Thread(pw); tmp.setName("PortWatcher Thread for "+host); tmp.start(); }
public void setPortForwardingR(int rport, String daemon, System.Object[] arg) { ChannelForwardedTCPIP.addPort(this, rport, daemon, arg); setPortForwarding(rport); }
internal static Tamir.SharpSsh.java.String[] guess(byte[] I_S, byte[] I_C) { //System.out.println("guess: "); Tamir.SharpSsh.java.String[] guess = new Tamir.SharpSsh.java.String[PROPOSAL_MAX]; Buffer sb = new Buffer(I_S); sb.setOffSet(17); Buffer cb = new Buffer(I_C); cb.setOffSet(17); for (int i = 0; i < PROPOSAL_MAX; i++) { byte[] sp = sb.getString(); // server proposal byte[] cp = cb.getString(); // client proposal //System.out.println("server-proposal: |"+new String(sp)+"|"); //System.out.println("client-proposal: |"+new String(cp)+"|"); int j = 0; int k = 0; //System.out.println(new String(cp)); //loop(using BREAK instead): while (j < cp.Length) { while (j < cp.Length && cp[j] != ',') { j++; } if (k == j) { return(null); } String algorithm = Util.getString(cp, k, j - k); //System.out.println("algorithm: "+algorithm); int l = 0; int m = 0; while (l < sp.Length) { while (l < sp.Length && sp[l] != ',') { l++; } if (m == l) { return(null); } //System.out.println(" "+new String(sp, m, l-m)); if (algorithm.Equals(Util.getString(sp, m, l - m))) { guess[i] = algorithm; //System.out.println(" "+algorithm); goto BREAK; } l++; m = l; } j++; k = j; } BREAK: if (j == 0) { guess[i] = ""; } else if (guess[i] == null) { //System.out.println(" fail"); return(null); } } // for(int i=0; i<PROPOSAL_MAX; i++){ // System.out.println("guess: ["+guess[i]+"]"); // } return(guess); }
public void delPortForwardingL(String boundaddress, int lport) { PortWatcher.delPort(this, boundaddress, lport); }
public void setPortForwardingR(int rport, String host, int lport, SocketFactory sf) { ChannelForwardedTCPIP.addPort(this, rport, host, lport, sf); setPortForwarding(rport); }
public void setPassword(String foo) { this.password=foo; }
internal PortWatcher(Session session, String address, int lport, String host, int rport, ServerSocketFactory factory) { this.session=session; this.lport=lport; this.host=host; this.rport=rport; try { boundaddress=InetAddress.getByName(address); ss=(factory==null) ? new ServerSocket(lport, 0, boundaddress) : factory.createServerSocket(lport, 0, boundaddress); } catch(Exception e) { Console.WriteLine(e); throw new JSchException("PortForwardingL: local port "+address+":"+lport+" cannot be bound."); } }
public void setPortForwardingL(int lport, String host, int rport) { setPortForwardingL("127.0.0.1", lport, host,rport); }
public void setClientVersion(String cv) { V_C=cv.getBytes(); }
public void setPortForwardingR(int rport, String host, int lport) { setPortForwardingR(rport, host, lport, (SocketFactory)null); }
/* cd /tmp c->s REALPATH s->c NAME c->s STAT s->c ATTR */ public void cd(String path) { //throws SftpException{ try { path=remoteAbsolutePath(path); Vector v=glob_remote(path); if(v.size()!=1) { throw new SftpException(SSH_FX_FAILURE, v.toString()); } path=(String)(v.elementAt(0)); sendREALPATH(path.getBytes()); Header _header=new Header(); _header=header(buf, _header); int length=_header.length; int type=_header.type; buf.rewind(); fill(buf.buffer, 0, length); if(type!=101 && type!=104) { throw new SftpException(SSH_FX_FAILURE, ""); } int i; if(type==101) { i=buf.getInt(); throwStatusError(buf, i); } i=buf.getInt(); byte[] str=buf.getString(); if(str!=null && str[0]!='/') { str=(cwd+"/"+new String(str)).getBytes(); } str=buf.getString(); // logname i=buf.getInt(); // attrs String newpwd=new String(str); SftpATTRS attr=_stat(newpwd); if((attr.getFlags()&SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS)==0) { throw new SftpException(SSH_FX_FAILURE, "Can't change directory: "+path); } if(!attr.isDir()) { throw new SftpException(SSH_FX_FAILURE, "Can't change directory: "+path); } cwd=newpwd; } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
//public void start(){ (new Thread(this)).start(); } public Channel openChannel(String type) { if(!_isConnected) { throw new JSchException("session is down"); } try { Channel channel=Channel.getChannel(type); addChannel(channel); channel.init(); return channel; } catch(Exception e) { System.Console.WriteLine(e); } return null; }
public void setPortForwardingR(int rport, String daemon) { setPortForwardingR(rport, daemon, null); }
public void run() { thread=this; byte[] foo; Buffer buf=new Buffer(); Packet packet=new Packet(buf); int i=0; Channel channel; int[] start=new int[1]; int[] length=new int[1]; KeyExchange kex=null; try { while(_isConnected && thread!=null) { buf=read(buf); int msgType=buf.buffer[5]&0xff; // if(msgType!=94) //System.Console.WriteLine("read: 94 ? "+msgType); if(kex!=null && kex.getState()==msgType) { bool result=kex.next(buf); if(!result) { throw new JSchException("verify: "+result); } continue; } switch(msgType) { case SSH_MSG_KEXINIT: //System.Console.WriteLine("KEXINIT"); kex=receive_kexinit(buf); break; case SSH_MSG_NEWKEYS: //System.Console.WriteLine("NEWKEYS"); send_newkeys(); receive_newkeys(buf, kex); kex=null; break; case SSH_MSG_CHANNEL_DATA: buf.getInt(); buf.getByte(); buf.getByte(); i=buf.getInt(); channel=Channel.getChannel(i, this); foo=buf.getString(start, length); if(channel==null) { break; } try { channel.write(foo, start[0], length[0]); } catch(Exception e) { //System.Console.WriteLine(e); try{channel.disconnect();} catch(Exception ee){} break; } int len=length[0]; channel.setLocalWindowSize(channel.lwsize-len); if(channel.lwsize<channel.lwsize_max/2) { packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_WINDOW_ADJUST); buf.putInt(channel.getRecipient()); buf.putInt(channel.lwsize_max-channel.lwsize); write(packet); channel.setLocalWindowSize(channel.lwsize_max); } break; case SSH_MSG_CHANNEL_EXTENDED_DATA: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); buf.getInt(); // data_type_code == 1 foo=buf.getString(start, length); //System.Console.WriteLine("stderr: "+new String(foo,start[0],length[0])); if(channel==null) { break; } //channel.write(foo, start[0], length[0]); channel.write_ext(foo, start[0], length[0]); len=length[0]; channel.setLocalWindowSize(channel.lwsize-len); if(channel.lwsize<channel.lwsize_max/2) { packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_WINDOW_ADJUST); buf.putInt(channel.getRecipient()); buf.putInt(channel.lwsize_max-channel.lwsize); write(packet); channel.setLocalWindowSize(channel.lwsize_max); } break; case SSH_MSG_CHANNEL_WINDOW_ADJUST: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel==null) { break; } channel.addRemoteWindowSize(buf.getInt()); break; case SSH_MSG_CHANNEL_EOF: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel!=null) { //channel._eof_remote=true; //channel.eof(); channel.eof_remote(); } /* packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_EOF); buf.putInt(channel.getRecipient()); write(packet); */ break; case SSH_MSG_CHANNEL_CLOSE: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel!=null) { // channel.close(); channel.disconnect(); } /* if(Channel.pool.size()==0){ thread=null; } */ break; case SSH_MSG_CHANNEL_OPEN_CONFIRMATION: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel==null) { //break; } channel.setRecipient(buf.getInt()); channel.setRemoteWindowSize(buf.getInt()); channel.setRemotePacketSize(buf.getInt()); break; case SSH_MSG_CHANNEL_OPEN_FAILURE: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel==null) { //break; } int reason_code=buf.getInt(); //foo=buf.getString(); // additional textual information //foo=buf.getString(); // language tag channel.exitstatus=reason_code; channel._close=true; channel._eof_remote=true; channel.setRecipient(0); break; case SSH_MSG_CHANNEL_REQUEST: buf.getInt(); buf.getShort(); i=buf.getInt(); foo=buf.getString(); bool reply=(buf.getByte()!=0); channel=Channel.getChannel(i, this); if(channel!=null) { byte reply_type=(byte)SSH_MSG_CHANNEL_FAILURE; if((new String(foo)).equals("exit-status")) { i=buf.getInt(); // exit-status channel.setExitStatus(i); // System.Console.WriteLine("exit-stauts: "+i); // channel.close(); reply_type=(byte)SSH_MSG_CHANNEL_SUCCESS; } if(reply) { packet.reset(); buf.putByte(reply_type); buf.putInt(channel.getRecipient()); write(packet); } } else { } break; case SSH_MSG_CHANNEL_OPEN: buf.getInt(); buf.getShort(); foo=buf.getString(); String ctyp=new String(foo); //System.Console.WriteLine("type="+ctyp); if(!new String("forwarded-tcpip").equals(ctyp) && !(new String("x11").equals(ctyp) && x11_forwarding)) { System.Console.WriteLine("Session.run: CHANNEL OPEN "+ctyp); throw new IOException("Session.run: CHANNEL OPEN "+ctyp); } else { channel=Channel.getChannel(ctyp); addChannel(channel); channel.getData(buf); channel.init(); packet.reset(); buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_CONFIRMATION); buf.putInt(channel.getRecipient()); buf.putInt(channel.id); buf.putInt(channel.lwsize); buf.putInt(channel.lmpsize); write(packet); Thread tmp=new Thread(channel); tmp.setName("Channel "+ctyp+" "+host); tmp.start(); break; } case SSH_MSG_CHANNEL_SUCCESS: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel==null) { break; } channel.reply=1; break; case SSH_MSG_CHANNEL_FAILURE: buf.getInt(); buf.getShort(); i=buf.getInt(); channel=Channel.getChannel(i, this); if(channel==null) { break; } channel.reply=0; break; case SSH_MSG_GLOBAL_REQUEST: buf.getInt(); buf.getShort(); foo=buf.getString(); // request name reply=(buf.getByte()!=0); if(reply) { packet.reset(); buf.putByte((byte)SSH_MSG_REQUEST_FAILURE); write(packet); } break; case SSH_MSG_REQUEST_FAILURE: case SSH_MSG_REQUEST_SUCCESS: Thread t=grr.getThread(); if(t!=null) { grr.setReply(msgType==SSH_MSG_REQUEST_SUCCESS? 1 : 0); t.interrupt(); } break; default: System.Console.WriteLine("Session.run: unsupported type "+msgType); throw new IOException("Unknown SSH message type "+msgType); } } } catch(Exception e) { //System.Console.WriteLine("# Session.run"); //e.printStackTrace(); } try { disconnect(); } catch(NullReferenceException e) { //System.Console.WriteLine("@1"); //e.printStackTrace(); } catch(Exception e) { //System.Console.WriteLine("@2"); //e.printStackTrace(); } _isConnected=false; }
public void setHost(String host) { this.host=host; }
public void chown(int uid, String path) { //throws SftpException{ try { path=remoteAbsolutePath(path); Vector v=glob_remote(path); int vsize=v.size(); for(int j=0; j<vsize; j++) { path=(String)(v.elementAt(j)); SftpATTRS attr=_stat(path); attr.setFLAGS(0); attr.setUIDGID(uid, attr.gid); _setStat(path, attr); } } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
void Tamir.SharpSsh.jsch.Proxy.connect(jsch::SocketFactory socket_factory, Tamir.SharpSsh.java.String host, int port, int timeout) { ch_e.setCommand(string.Format("nc {0} {1}", host, port)); istr = ch_e.getInputStream(); // 向こう→こっち ostr = ch_e.getOutputStream(); // こっち→向こう ch_e.connect(); }
public void setX11Cookie(String cookie) { ChannelX11.setCookie(cookie); }
public void setPortForwardingL(String boundaddress, int lport, String host, int rport) { setPortForwardingL(boundaddress, lport, host, rport, null); }
internal static void delPort(Session session, String address, int lport) { PortWatcher pw=getPort(session, address, lport); if(pw==null) { throw new JSchException("PortForwardingL: local port "+address+":"+lport+" is not registered."); } pw.delete(); pool.removeElement(pw); }
public void setX11Host(String host) { ChannelX11.setHost(host); }
internal void setUserName(String foo) { this.username=foo; }
private void checkHost(String host, KeyExchange kex) { String shkc=getConfig("StrictHostKeyChecking"); //System.Console.WriteLine("shkc: "+shkc); byte[] K_S=kex.getHostKey(); String key_type=kex.getKeyType(); String key_fprint=kex.getFingerPrint(); hostkey=new HostKey(host, K_S); HostKeyRepository hkr=jsch.getHostKeyRepository(); int i=0; lock(hkr) { i=hkr.check(host, K_S); } bool insert=false; if((shkc.equals("ask") || shkc.equals("yes")) && i==HostKeyRepository.CHANGED) { String file=null; lock(hkr) { file=hkr.getKnownHostsRepositoryID(); } if(file==null){file="known_hosts";} String message= "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!\n"+ "IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n"+ "Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n"+ "It is also possible that the "+key_type+" host key has just been changed.\n"+ "The fingerprint for the "+key_type+" key sent by the remote host is\n"+ key_fprint+".\n"+ "Please contact your system administrator.\n"+ "Add correct host key in "+file+" to get rid of this message."; bool b=false; if(userinfo!=null) { //userinfo.showMessage(message); b=userinfo.promptYesNo(message+ "\nDo you want to delete the old key and insert the new key?"); } //throw new JSchException("HostKey has been changed: "+host); if(!b) { throw new JSchException("HostKey has been changed: "+host); } else { lock(hkr) { hkr.remove(host, (key_type.equals("DSA") ? "ssh-dss" : "ssh-rsa"), null); insert=true; } } } // bool insert=false; if((shkc.equals("ask") || shkc.equals("yes")) && (i!=HostKeyRepository.OK) && !insert) { if(shkc.equals("yes")) { throw new JSchException("reject HostKey: "+host); } //System.Console.WriteLine("finger-print: "+key_fprint); if(userinfo!=null) { bool foo=userinfo.promptYesNo( "The authenticity of host '"+host+"' can't be established.\n"+ key_type+" key fingerprint is "+key_fprint+".\n"+ "Are you sure you want to continue connecting?" ); if(!foo) { throw new JSchException("reject HostKey: "+host); } insert=true; } else { if(i==HostKeyRepository.NOT_INCLUDED) throw new JSchException("UnknownHostKey: "+host+". "+key_type+" key fingerprint is "+key_fprint); else throw new JSchException("HostKey has been changed: "+host); } } if(shkc.equals("no") && HostKeyRepository.NOT_INCLUDED==i) { insert=true; } if(insert) { lock(hkr) { hkr.add(host, K_S, userinfo); } } }
internal static PortWatcher addPort(Session session, String address, int lport, String host, int rport, ServerSocketFactory ssf) { if(getPort(session, address, lport)!=null) { throw new JSchException("PortForwardingL: local port "+ address+":"+lport+" is already registered."); } PortWatcher pw=new PortWatcher(session, address, lport, host, rport, ssf); pool.addElement(pw); return pw; }
void Tamir.SharpSsh.jsch.Proxy.connect(jsch::SocketFactory socket_factory, Tamir.SharpSsh.java.String host, int port, int timeout) { System.Console.WriteLine("MyProx.connect(factory,host={0},port={1},timeout={2})", host, port, timeout); ch_e.setCommand(string.Format("nc {0} {1}", host, port)); //istr=new StreamTee("istr",ch_e.getInputStream()); // 向こう→こっち //ostr=new StreamTee("ostr",ch_e.getOutputStream()); // こっち→向こう istr = ch_e.getInputStream(); // 向こう→こっち ostr = ch_e.getOutputStream(); // こっち→向こう ch_e.connect(); }