//获取SFTP文件列表
        public ArrayList GetFileList(string remotePath, string fileType)
        {
            try
            {
                Tamir.SharpSsh.java.util.Vector vvv = m_sftp.ls(remotePath);
                ArrayList objList = new ArrayList();
                foreach (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry qqq in vvv)
                {
                    string sss = qqq.getFilename();
                    if (sss.Length > (fileType.Length + 1) && fileType == sss.Substring(sss.Length - fileType.Length))
                    {
                        objList.Add(sss);
                    }
                    else
                    {
                        continue;
                    }
                }

                return(objList);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
		private Vector glob_local(String _path) 
		{ //throws Exception{
			//System.out.println("glob_local: "+_path);
			Vector v=new Vector();
			byte[] path=_path.getBytes();
			int i=path.Length-1;
			while(i>=0){if(path[i]=='*' || path[i]=='?')break;i--;}
			if(i<0){ v.addElement(_path); return v;}
			while(i>=0){if(path[i]==file_separatorc)break;i--;}
			if(i<0){ v.addElement(_path); return v;}
			byte[] dir;
			if(i==0){dir=new byte[]{(byte)file_separatorc};}
			else
			{
				dir=new byte[i];
				Tamir.SharpSsh.java.System.arraycopy(path, 0, dir, 0, i);
			}
			byte[] pattern=new byte[path.Length-i-1];
			Tamir.SharpSsh.java.System.arraycopy(path, i+1, pattern, 0, pattern.Length);
			//System.out.println("dir: "+new String(dir)+" pattern: "+new String(pattern));
			try
			{
				String[] children=(new File(new String(dir))).list();
				for(int j=0; j<children.Length; j++)
				{
					//System.out.println("children: "+children[j]);
					if(Util.glob(pattern, children[j].getBytes()))
					{
						v.addElement(new String(dir)+file_separator+children[j]);
					}
				}
			}
			catch(Exception e)
			{
			}
			return v;
		}
Beispiel #3
0
		private Vector glob_remote(String _path)
		{
			//throws Exception{
			//System.err.println("glob_remote: "+_path);
			Vector v=new Vector();
			byte[] path=_path.getBytes();
			if(!isPattern(path))
			{
				v.addElement(Util.unquote(_path)); return v;
			}
			int i=path.Length-1;
			while(i>=0){if(path[i]=='/')break;i--;}
			if(i<0){ v.addElement(Util.unquote(_path)); return v;}
			byte[] dir;
			if(i==0){dir=new byte[]{(byte)'/'};}
			else
			{ 
				dir=new byte[i];
				java.System.arraycopy(path, 0, dir, 0, i);
			}
			//System.err.println("dir: "+new String(dir));
			byte[] pattern=new byte[path.Length-i-1];
			java.System.arraycopy(path, i+1, pattern, 0, pattern.Length);
			//System.err.println("file: "+new String(pattern));

			sendOPENDIR(dir);

			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)
			{
				i=buf.getInt();
				throwStatusError(buf, i);
			}

			byte[] handle=buf.getString();         // filename

			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);
					break;
				}

				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);
						i=io.ins.read(buf.buffer, buf.index, j);
						if(i<=0)break;
						buf.index+=i;
						length-=i;
					}

					byte[] filename=buf.getString();
					//System.err.println("filename: "+new String(filename));
					str=buf.getString();
					SftpATTRS attrs=SftpATTRS.getATTR(buf);

					if(Util.glob(pattern, filename))
					{
						v.addElement(new String(dir)+"/"+new String(filename));
					}
					count--; 
				}
			}
			if(_sendCLOSE(handle, _header)) 
				return v;
			return null;
		}