Пример #1
0
		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;
		}
Пример #2
0
		public java.util.Vector ls(String path) 
		{ //throws SftpException{
			try
			{
				path=remoteAbsolutePath(path);

				String dir=path;
				byte[] pattern=null;
				SftpATTRS attr=null;
				if(isPattern(dir) || 
					((attr=stat(dir))!=null && !attr.isDir()))
				{
					int foo=path.lastIndexOf('/');
					dir=path.substring(0, ((foo==0)?1:foo));
					pattern=path.substring(foo+1).getBytes();
				}

				sendOPENDIR(dir.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

				java.util.Vector v=new java.util.Vector();
				while(true)
				{
					sendREADDIR(handle);

					_header=header(buf, _header);
					length=_header.length;
					type=_header.type;
					if(type!=SSH_FXP_STATUS && type!=SSH_FXP_NAME)
					{
						throw new SftpException(SSH_FX_FAILURE, "");
					}
					if(type==SSH_FXP_STATUS)
					{ 
						buf.rewind();
						fill(buf.buffer, 0, length);
						int i=buf.getInt();
						if(i==SSH_FX_EOF)
							break;
						throwStatusError(buf, i);
					}

					buf.rewind();
					fill(buf.buffer, 0, 4); length-=4;
					int count=buf.getInt();

					byte[] str;
					int flags;

					buf.reset();
					while(count>0)
					{
						if(length>0)
						{
							buf.shift();
							int j=(buf.buffer.Length>(buf.index+length)) ? length : (buf.buffer.Length-buf.index);
							int i=fill(buf.buffer, buf.index, j);
							buf.index+=i;
							length-=i;
						}
						byte[] filename=buf.getString();
						str=buf.getString();
						String longname=new String(str);

						SftpATTRS attrs=SftpATTRS.getATTR(buf);
						if(pattern==null || Util.glob(pattern, filename))
						{
							v.addElement(new LsEntry(new String(filename), longname, attrs));
						}

						count--; 
					}
				}
				_sendCLOSE(handle, _header);
				return v;
			}
			catch(Exception e)
			{
				if(e is SftpException) throw (SftpException)e;
				throw new SftpException(SSH_FX_FAILURE, "");
			}
		}