//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 e) { Debug.LogError(e); return(false); } }
//SFTP存放文件 public bool Put(string localPath, string remotePath, Callback onProgressCallback, Callback onFinishCallback) { try { Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(localPath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); ProgressMonitor progressMonitor = new ProgressMonitor(onProgressCallback, onFinishCallback); m_sftp.put(src, dst, progressMonitor, ChannelSftp.OVERWRITE); return(true); } catch (Exception e) { Debug.LogError(e); return(false); } }
//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); } }
//SFTP存放文件 public bool Put(byte[] fileContent, string remotePath) { try { Stream memStream = new MemoryStream(fileContent); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); PutStream(memStream, remotePath); return(true); } catch (Exception ex) { return(false); } }
public bool PutStream(System.IO.Stream localFile, string remotePath) { try { Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(remotePath); m_sftp.put(new Tamir.Streams.InputStreamWrapper(localFile), dst, 1); localFile.Dispose(); return(true); } catch (Exception ex) { throw ex; } }
//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); sftp.put(src, dst); return(true); } catch (Exception ex) { UnityEngine.Debug.LogError(ex.Message); return(false); } }
public ProxyHTTP(String proxy_host) { int port=DEFAULTPORT; String host=proxy_host; if(proxy_host.indexOf(':')!=-1) { try { host=proxy_host.substring(0, proxy_host.indexOf(':')); port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1)); } catch(Exception e) { } } this.proxy_host=host; this.proxy_port=port; }
//SFTP获取文件 public bool Get(string remotePath, string localPath) { try { string dirPath = localPath.Substring(0, localPath.LastIndexOf('/')); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); } //if (!System.IO.File.Exists(localPath)) //{ // System.IO.File.Create(localPath).Dispose(); //} Tamir.SharpSsh.java.String src = new Tamir.SharpSsh.java.String(remotePath); Tamir.SharpSsh.java.String dst = new Tamir.SharpSsh.java.String(localPath); sftp.get(src, dst); return(true); } catch (Exception ex) { UnityEngine.Debug.LogError(ex.Message); 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 setPortForwardingL(String boundaddress, int lport, String host, int rport) { setPortForwardingL(boundaddress, lport, host, rport, null); }
public void setPortForwardingL(int lport, String host, int rport) { setPortForwardingL("127.0.0.1", lport, host,rport); }
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 setPortForwardingR(int rport, String host, int lport, SocketFactory sf) { ChannelForwardedTCPIP.addPort(this, rport, host, lport, sf); setPortForwarding(rport); }
public void get(String src, OutputStream dst) { //throws SftpException{ get(src, dst, null, OVERWRITE, 0); }
internal void setUserName(String foo){ this.username=foo; }
public void setX11Host(String host){ ChannelX11.setHost(host); }
/**/ public OutputStream put(String dst) { //throws SftpException{ return put(dst, (SftpProgressMonitor)null, OVERWRITE); } public OutputStream put(String dst, int mode) { //throws SftpException{ return put(dst, (SftpProgressMonitor)null, mode); } public OutputStream put(String dst, SftpProgressMonitor monitor, int mode) { //throws SftpException{ return put(dst, monitor, mode, 0); } public OutputStream put(String dst, SftpProgressMonitor monitor, int mode, long offset) { dst=remoteAbsolutePath(dst); try { Vector v=glob_remote(dst); if(v.size()!=1) { throw new SftpException(SSH_FX_FAILURE, v.toString()); } dst=(String)(v.elementAt(0)); if(isRemoteDir(dst)) { throw new SftpException(SSH_FX_FAILURE, dst+" is a directory"); } long skip=0; if(mode==RESUME || mode==APPEND) { try { SftpATTRS attr=stat(dst); skip=attr.getSize(); } catch(Exception eee) { //System.out.println(eee); } } if(mode==OVERWRITE){ sendOPENW(dst.getBytes()); } else{ sendOPENA(dst.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!=SSH_FXP_STATUS && type!=SSH_FXP_HANDLE) { throw new SftpException(SSH_FX_FAILURE, ""); } if(type==SSH_FXP_STATUS) { int i=buf.getInt(); throwStatusError(buf, i); } byte[] handle=buf.getString(); // filename //long offset=0; if(mode==RESUME || mode==APPEND) { offset+=skip; } long[] _offset=new long[1]; _offset[0]=offset; OutputStream outs = new OutputStreamPut(this,handle,_offset,monitor); // private bool init=true; // private int[] ackid=new int[1]; // private int startid=0; // private int _ackid=0; // private int ackcount=0; // public void write(byte[] d, int s, int len) { //throws java.io.IOException{ // if(init){ // startid=count; // _ackid=count; // init=false; // } // try{ // int _len=len; // while(_len>0){ // _len-=sendWRITE(handle, _offset[0], d, s, _len); // if((count-1)==startid || // io.ins.available()>=1024){ // while(io.ins.available()>0){ // if(checkStatus(ackid)){ // _ackid=ackid[0]; // if(startid>_ackid || _ackid>count-1){ // throw new SftpException(SSH_FX_FAILURE, ""); // } // ackcount++; // } // else{ // break; // } // } // } // } // _offset[0]+=len; // if(monitor!=null && !monitor.count(len)){ // throw new IOException("canceled"); // } // } // catch(IOException e){ throw e; } // catch(Exception e){ throw new IOException(e.toString()); } // } // byte[] _data=new byte[1]; // public void write(int foo) { //throws java.io.IOException{ // _data[0]=(byte)foo; // write(_data, 0, 1); // } // public void close() { //throws java.io.IOException{ // try{ // int _ackcount=count-startid; // while(_ackcount>ackcount){ // if(!checkStatus(null)){ // break; // } // ackcount++; // } // } // catch(SftpException e){ // throw new IOException(e.toString()); // } // if(monitor!=null)monitor.end(); // try{ _sendCLOSE(handle); } // catch(IOException e){ throw e; } // catch(Exception e){ // throw new IOException(e.toString()); // } // } //}; return outs; } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } } /**/ public void get(String src, String dst) { //throws SftpException{ get(src, dst, null, OVERWRITE); }
public void setPortForwardingR(int rport, String daemon, System.Object[] arg) { ChannelForwardedTCPIP.addPort(this, rport, daemon, arg); setPortForwarding(rport); }
public void get(String src, String dst, SftpProgressMonitor monitor) { //throws SftpException{ get(src, dst, monitor, OVERWRITE); }
public void get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) { //throws SftpException{ //try //{ src=remoteAbsolutePath(src); Vector v=glob_remote(src); if(v.size()!=1) { throw new SftpException(SSH_FX_FAILURE, v.toString()); } src=(String)(v.elementAt(0)); if(monitor!=null) { SftpATTRS attr=_stat(src); monitor.init(SftpProgressMonitor.GET, src, "??", attr.getSize()); if(mode==RESUME) { monitor.count(skip); } } _get(src, dst, monitor, mode, skip); //} //catch(Exception e) //{ // if(e is SftpException) throw (SftpException)e; // throw new SftpException(SSH_FX_FAILURE, ""); //} }
public void get(String src, OutputStream dst, SftpProgressMonitor monitor) { //throws SftpException{ get(src, dst, monitor, OVERWRITE, 0); }
public void delPortForwardingL(String boundaddress, int lport) { PortWatcher.delPort(this, boundaddress, lport); }
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 setPortForwardingR(int rport, String daemon) { setPortForwardingR(rport, daemon, null); }
public void get(String src, String dst, SftpProgressMonitor monitor, int mode) { //throws SftpException{ src=remoteAbsolutePath(src); dst=localAbsolutePath(dst); try { Vector v=glob_remote(src); int vsize=v.size(); if(vsize==0) { throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file"); } File dstFile=new File(dst); bool isDstDir=dstFile.isDirectory(); StringBuffer dstsb=null; if(isDstDir) { if(!dst.endsWith(file_separator)) { dst+=file_separator; } dstsb=new StringBuffer(dst); } else if(vsize>1) { throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file."); } for(int j=0; j<vsize; j++) { String _src=(String)(v.elementAt(j)); SftpATTRS attr=_stat(_src); if(attr.isDir()) { throw new SftpException(SSH_FX_FAILURE, "not supported to get directory "+_src); } String _dst=null; if(isDstDir) { int i=_src.lastIndexOf('/'); if(i==-1) dstsb.append(_src); else dstsb.append(_src.substring(i + 1)); _dst=dstsb.toString(); dstsb.delete(dst.length(), _dst.length()); } else { _dst=dst; } if(mode==RESUME) { long size_of_src=attr.getSize(); long size_of_dst=new File(_dst).length(); if(size_of_dst>size_of_src) { throw new SftpException(SSH_FX_FAILURE, "failed to resume for "+_dst); } if(size_of_dst==size_of_src) { return; } } if(monitor!=null) { monitor.init(SftpProgressMonitor.GET, _src, _dst, attr.getSize()); if(mode==RESUME) { monitor.count(new File(_dst).length()); } } FileOutputStream fos=null; if(mode==OVERWRITE) { fos=new FileOutputStream(_dst); } else { fos=new FileOutputStream(_dst, true); // append } //System.err.println("_get: "+_src+", "+_dst); _get(_src, fos, monitor, mode, new File(_dst).length()); fos.close(); } } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
public void setHost(String host){ this.host=host; }
public ProxyHTTP(String proxy_host, int proxy_port) { this.proxy_host=proxy_host; this.proxy_port=proxy_port; }
public void setPassword(String foo){ this.password=foo; }
public void setUserPasswd(String user, String passwd) { this.user=user; this.passwd=passwd; }
public void setX11Cookie(String cookie){ ChannelX11.setCookie(cookie); }
public void connect(SocketFactory socket_factory, String host, int port, int timeout) { try { if(socket_factory==null) { socket=Util.createSocket(proxy_host, proxy_port, timeout); ins= new JStream(socket.getInputStream()); outs=new JStream(socket.getOutputStream()); } else { socket=socket_factory.createSocket(proxy_host, proxy_port); ins=new JStream(socket_factory.getInputStream(socket)); outs=new JStream(socket_factory.getOutputStream(socket)); } if(timeout>0) { socket.setSoTimeout(timeout); } socket.setTcpNoDelay(true); outs.write(new String("CONNECT "+host+":"+port+" HTTP/1.0\r\n").getBytes()); if(user!=null && passwd!=null) { byte[] _code=(user+":"+passwd).getBytes(); _code=Util.toBase64(_code, 0, _code.Length); outs.write(new String("Proxy-Authorization: Basic ").getBytes()); outs.write(_code); outs.write(new String("\r\n").getBytes()); } outs.write(new String("\r\n").getBytes()); outs.flush(); int foo=0; StringBuffer sb=new StringBuffer(); while(foo>=0) { foo=ins.read(); if(foo!=13){sb.append((char)foo); continue;} foo=ins.read(); if(foo!=10){continue;} break; } if(foo<0) { throw new System.IO.IOException(); } String response=sb.toString(); String reason="Unknow reason"; int code=-1; try { foo=response.indexOf(' '); int bar=response.indexOf(' ', foo+1); code=Integer.parseInt(response.substring(foo+1, bar)); reason=response.substring(bar+1); } catch(Exception e) { } if(code!=200) { throw new System.IO.IOException("proxy error: "+reason); } /* while(foo>=0){ foo=in.read(); if(foo!=13) continue; foo=in.read(); if(foo!=10) continue; foo=in.read(); if(foo!=13) continue; foo=in.read(); if(foo!=10) continue; break; } */ int count=0; while(true) { count=0; while(foo>=0) { foo=ins.read(); if(foo!=13){count++; continue;} foo=ins.read(); if(foo!=10){continue;} break; } if(foo<0) { throw new System.IO.IOException(); } if(count==0)break; } } catch(RuntimeException e) { throw e; } catch(Exception e) { try{ if(socket!=null)socket.close(); } catch(Exception eee) { } String message="ProxyHTTP: "+e.toString(); throw e; } }
public override bool start(Session session) { base.start(session); //System.out.println("UserAuthNone: start"); Packet packet=session.packet; Buffer buf=session.buf; String username=session.username; byte[] _username=null; try{ _username=Util.getBytesUTF8(username); } catch {//(java.io.UnsupportedEncodingException e){ _username=Util.getBytes(username); } // send // byte SSH_MSG_USERAUTH_REQUEST(50) // string user name // string service name ("ssh-connection") // string "none" packet.reset(); buf.putByte((byte)Session.SSH_MSG_USERAUTH_REQUEST); buf.putString(_username); buf.putString(Util.getBytes("ssh-connection")); buf.putString(Util.getBytes("none")); session.write(packet); loop: while(true) { // receive // byte SSH_MSG_USERAUTH_SUCCESS(52) // string service name buf=session.read(buf); //System.out.println("UserAuthNone: read: 52 ? "+ buf.buffer[5]); if(buf.buffer[5]==Session.SSH_MSG_USERAUTH_SUCCESS) { return true; } if(buf.buffer[5]==Session.SSH_MSG_USERAUTH_BANNER) { buf.getInt(); buf.getByte(); buf.getByte(); byte[] _message=buf.getString(); byte[] lang=buf.getString(); String message=null; try{ message=Util.getStringUTF8(_message); } catch {//(java.io.UnsupportedEncodingException e){ message=Util.getString(_message); } if(userinfo!=null) { userinfo.showMessage(message); } goto loop; } if(buf.buffer[5]==Session.SSH_MSG_USERAUTH_FAILURE) { buf.getInt(); buf.getByte(); buf.getByte(); byte[] foo=buf.getString(); int partial_success=buf.getByte(); methods=Util.getString(foo); //System.out.println("UserAuthNONE: "+methods+ // " partial_success:"+(partial_success!=0)); // if(partial_success!=0){ // throw new JSchPartialAuthException(new String(foo)); // } break; } else { // System.out.println("USERAUTH fail ("+buf.buffer[5]+")"); throw new JSchException("USERAUTH fail ("+buf.buffer[5]+")"); } } //throw new JSchException("USERAUTH fail"); return false; }
//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 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, ""); } }
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); } } }