static private unquote ( String path ) : String | ||
path | String | |
return | String |
private ArrayList glob_remote(String _path) { //System.err.println("glob_remote: "+_path); ArrayList v = new ArrayList(); byte[] path = Encoding.UTF8.GetBytes(_path); if (!IsPattern(path)) { v.Add(Util.unquote(_path)); return(v); } int i = path.Length - 1; while (i >= 0) { if (path[i] == '/') { break; } i--; } if (i < 0) { v.Add(Util.unquote(_path)); return(v); } byte[] dir; if (i == 0) { dir = new byte[] { (byte)'/' }; } else { dir = new byte[i]; System.Array.Copy(path, 0, dir, 0, i); } //System.err.println("dir: "+Encoding.UTF8.GetString(dir)); byte[] pattern = new byte[path.Length - i - 1]; System.Array.Copy(path, i + 1, pattern, 0, pattern.Length); //System.err.println("file: "+Encoding.UTF8.GetString(pattern)); sendOPENDIR(dir); Header _header = new Header(); _header = ReadHeader(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.ReadInt(); throwStatusError(buf, i); } byte[] handle = buf.ReadString(); // filename while (true) { sendREADDIR(handle); _header = ReadHeader(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.ReadInt(); 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.ReadString(); //System.err.println("filename: "+Encoding.UTF8.GetString(filename)); str = buf.ReadString(); SftpATTRS attrs = SftpATTRS.getATTR(buf); if (Util.glob(pattern, filename)) { v.Add(Encoding.UTF8.GetString(dir) + "/" + Encoding.UTF8.GetString(filename)); } count--; } } if (_sendCLOSE(handle, _header)) { return(v); } return(null); }