private void sendSETSTAT(String path, SftpATTRS attr) { packet.reset(); putHEAD(SSH_FXP_SETSTAT, 9 + path.Length + attr.Length()); buf.WriteInt(seq++); buf.WriteString(path); // path attr.dump(buf); session.write(packet, this, 9 + path.Length + attr.Length() + 4); }
internal static SftpATTRS getATTR(Buffer buf) { SftpATTRS attr = new SftpATTRS(); attr.flags = (uint)buf.getInt(); if ((attr.flags & SSH_FILEXFER_ATTR_SIZE) != 0) { attr.size = buf.getLong(); } if ((attr.flags & SSH_FILEXFER_ATTR_UIDGID) != 0) { attr.uid = buf.getInt(); attr.gid = buf.getInt(); } if ((attr.flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0) { attr.permissions = buf.getInt(); } if ((attr.flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.atime = buf.getInt(); } if ((attr.flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.mtime = buf.getInt(); } /* * if ((attr.flags & SSH_FILEXFER_ATTR_CREATETIME) != 0) * { * attr.ctime=buf.getInt(); * } * if ((attr.flags & SSH_FILEXFER_ATTR_MODIFYTIME) != 0) * { * attr.mtime=buf.getInt(); * } */ if ((attr.flags & SSH_FILEXFER_ATTR_EXTENDED) != 0) { int count = buf.getInt(); if (count > 0) { attr.extended = new String[count * 2]; for (int i = 0; i < count; i++) { attr.extended[i * 2] = Util.getString(buf.getString()); attr.extended[i * 2 + 1] = Util.getString(buf.getString()); } } } return(attr); }
private void sendMKDIR(String path, SftpATTRS attr) { packet.reset(); putHEAD(SSH_FXP_MKDIR, 9 + path.Length + (attr != null ? attr.Length() : 4)); buf.WriteInt(seq++); buf.WriteString(path); // path if (attr != null) { attr.dump(buf); } else { buf.WriteInt(0); } session.write(packet, this, 9 + path.Length + (attr != null ? attr.Length() : 4) + 4); }
internal static SftpATTRS getATTR(Buffer buf) { SftpATTRS attr = new SftpATTRS(); attr.Flags = buf.ReadInt(); if ((attr.Flags & SSH_FILEXFER_ATTR_SIZE) != 0) { attr._Size = buf.ReadLong(); } if ((attr.Flags & SSH_FILEXFER_ATTR_UIDGID) != 0) { attr.uid = buf.ReadInt(); attr.gid = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0) { attr._Permissions = (PermissionFlags)buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.AccessTime = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.ModificationTime = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_EXTENDED) != 0) { int count = buf.ReadInt(); if (count > 0) { attr.extended = new String[count * 2]; for (int i = 0; i < count; i++) { attr.extended[i * 2] = Util.getString(buf.ReadString()); attr.extended[i * 2 + 1] = Util.getString(buf.ReadString()); } } } return(attr); }
internal LsEntry(String filename, String longname, SftpATTRS attrs) { setFilename(filename); setLongname(longname); setAttrs(attrs); }
private void sendMKDIR(byte[] path, SftpATTRS attr) { //throws Exception{ packet.reset(); putHEAD(SSH_FXP_MKDIR, 9+path.Length+(attr!=null?attr.Length():4)); buf.putInt(seq++); buf.putString(path); // path if(attr!=null) attr.dump(buf); else buf.putInt(0); session.write(packet, this, 9+path.Length+(attr!=null?attr.Length():4)+4); }
private void sendSETSTAT(byte[] path, SftpATTRS attr) { //throws Exception{ packet.reset(); putHEAD(SSH_FXP_SETSTAT, 9+path.Length+attr.Length()); buf.putInt(seq++); buf.putString(path); // path attr.dump(buf); session.write(packet, this, 9+path.Length+attr.Length()+4); }
private void _setStat(String path, SftpATTRS attr) { //throws SftpException{ try { sendSETSTAT(path.getBytes(), attr); 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) { throw new SftpException(SSH_FX_FAILURE, ""); } int i=buf.getInt(); if(i!=SSH_FX_OK) { throwStatusError(buf, i); } } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
public void setStat(String path, SftpATTRS attr) { //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)); _setStat(path, attr); } } catch(Exception e) { if(e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
public void setStat(String path, SftpATTRS attr) { //throws SftpException{ try { path = RemoteAbsolutePath(path); ArrayList v = glob_remote(path); int vsize = v.Count; for (int j = 0; j < vsize; j++) { path = (String)(v[j]); _setStat(path, attr); } } catch (Exception e) { if (e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
internal static SftpATTRS getATTR(Buffer buf) { SftpATTRS attr = new SftpATTRS(); attr.Flags = buf.ReadInt(); if ((attr.Flags & SSH_FILEXFER_ATTR_SIZE) != 0) { attr._Size = buf.ReadLong(); } if ((attr.Flags & SSH_FILEXFER_ATTR_UIDGID) != 0) { attr.uid = buf.ReadInt(); attr.gid = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0) { attr._Permissions = (PermissionFlags)buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.AccessTime = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_ACMODTIME) != 0) { attr.ModificationTime = buf.ReadInt(); } if ((attr.Flags & SSH_FILEXFER_ATTR_EXTENDED) != 0) { int count = buf.ReadInt(); if (count > 0) { attr.extended = new String[count * 2]; for (int i = 0; i < count; i++) { attr.extended[i * 2] = Util.getString(buf.ReadString()); attr.extended[i * 2 + 1] = Util.getString(buf.ReadString()); } } } return attr; }
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); }
void setAttrs(SftpATTRS attrs) {this.attrs = attrs;}
public void chmod(SftpATTRS.PermissionFlags permissions, String path) { //throws SftpException{ try { path = RemoteAbsolutePath(path); ArrayList v = glob_remote(path); int vsize = v.Count; for (int j = 0; j < vsize; j++) { path = (String)(v[j]); SftpATTRS attr = _stat(path); attr.Flags = 0; attr.Permissions = permissions; _setStat(path, attr); } } catch (Exception e) { if (e is SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } }
internal static SftpATTRS getATTR(Buffer buf) { SftpATTRS attr=new SftpATTRS(); attr.flags=buf.getInt(); if((attr.flags&SSH_FILEXFER_ATTR_SIZE)!=0){ attr.size=buf.getLong(); } if((attr.flags&SSH_FILEXFER_ATTR_UIDGID)!=0) { attr.uid=buf.getInt(); attr.gid=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0) { attr.permissions=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0) { attr.atime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0) { attr.mtime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_EXTENDED)!=0) { int count=buf.getInt(); if(count>0) { attr.extended=new String[count*2]; for(int i=0; i<count; i++) { attr.extended[i*2]=Util.getString(buf.getString()); attr.extended[i*2+1]=Util.getString(buf.getString()); } } } return attr; }
public LsEntry(String filename, String path, String longname, SftpATTRS attrs) { Filename = filename; Path = path; Longname = longname; Attributes = attrs; }