/// <summary> /// Executes the specified CL command string and returns the result. /// The command must be non-interactive. /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public CommandResult execute(String cmd) throws IOException public virtual CommandResult execute(string cmd) { if (Closed) { throw new IOException("Connection closed"); } sendRunCommandRequest(out_, cmd, datastreamLevel_); out_.flush(); int length = in_.readInt(); if (length < 20) { throw DataStreamException.badLength("commandRunCommand", length); } in_.skipBytes(16); int rc = in_.readShort(); if (rc != 0 && rc != 0x0400) { in_.skipBytes(length - 22); throw DataStreamException.badReturnCode("commandRunCommand", rc); } Message[] messages = getMessages(length); in_.end(); return(new CommandResult(rc == 0, messages, rc)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static FileConnection getConnection(final boolean isSSL, SystemInfo info, String user, String password, int filePort) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public static FileConnection getConnection(bool isSSL, SystemInfo info, string user, string password, int filePort) { if (filePort < 0 || filePort > 65535) { throw new IOException("Bad file port: " + filePort); } FileConnection conn = null; Socket fileServer = isSSL? SSLSocketFactory.Default.createSocket(info.System, filePort) : new Socket(info.System, filePort); Stream @in = fileServer.InputStream; Stream @out = fileServer.OutputStream; try { HostOutputStream dout = new HostOutputStream(new BufferedOutputStream(@out)); HostInputStream din = new HostInputStream(new BufferedInputStream(@in)); string jobName = connect(info, dout, din, 0xE002, user, password); sendExchangeAttributesRequest(dout); dout.flush(); int length = din.readInt(); if (length < 22) { throw DataStreamException.badLength("fileExchangeAttributes", length); } din.skipBytes(16); int rc = din.readShort(); if (rc != 0) { throw DataStreamException.badReturnCode("fileExchangeAttributes", rc); } int datastreamLevel = din.readShort(); din.skipBytes(2); int maxDataBlockSize = din.readInt(); //int ccsidLL = din.readInt(); //int ccsidCP = din.readShort(); din.skipBytes(6); int ccsid = din.readShort(); int remaining = length - 38; din.skipBytes(remaining); conn = new FileConnection(info, fileServer, din, dout, ccsid, datastreamLevel, maxDataBlockSize, user, jobName); return(conn); } finally { if (conn == null) { @in.Close(); @out.Close(); fileServer.close(); } } }
/// <summary> /// Returns a list of filenames under the specified directory or file spec. /// For example, these all return the same file listing: /// <ul> /// <li>list("/home/smith")</li> /// <li>list("/home/smith/*")</li> /// <li>list("/home/smith/../smith")</li> /// </ul> /// To return more than just the names of files, use <seealso cref="#listFiles listFiles()"/>. /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public java.util.List<String> list(String dir) throws IOException public virtual IList <string> list(string dir) { // System.out.println("Server CCSID: "+getInfo().getServerCCSID()); if (dir.IndexOf("*", StringComparison.Ordinal) < 0) { if (!dir.EndsWith("/", StringComparison.Ordinal)) { dir = dir + "/*"; } else { dir = dir + "*"; } } sendListFilesRequest(Conv.stringToUnicodeByteArray(dir)); out_.flush(); List <string> files = new List <string>(); int chain = 1; while (chain != 0) { int length = in_.readInt(); if (length < 24) { throw DataStreamException.badLength("listFiles", length); } int headerID = in_.readShort(); int serverID = in_.readShort(); int csInstance = in_.readInt(); int correlationID = in_.readInt(); int templateLength = in_.readShort(); int reqRepID = in_.readShort(); chain = in_.readShort(); if (reqRepID == 0x8001) { int rc = in_.readShort(); int remaining = length - 24; in_.skipBytes(remaining); if (rc != FileConstants.RC_NO_MORE_FILES) { throw DataStreamException.badReturnCode("listFiles", rc); } } else if (reqRepID == 0x8005) { int numRead = 22; /* long createDate = in_.readLong(); * long modifyDate = in_.readLong(); * long actual = ((modifyDate >> 32) & 0x00FFFFFFFFL)*1000L + ((modifyDate & 0x00FFFFFFFFL)/1000); * System.out.println(new java.util.Date(actual)); * long accessDate = in_.readLong(); * int fileSize = in_.readInt(); * int fixedAttributes = in_.readInt(); * int objectType = in_.readShort(); * int numExtAttrs = in_.readShort(); * int bytesEANames = in_.readInt(); * int bytesEAValues = in_.readInt(); * int version = in_.readInt(); * int amountAccessed = in_.readShort(); * int accessHistory = in_.readByte(); * int fileCCSID = in_.readShort(); * int checkoutCCSID = in_.readShort(); * int restartID = in_.readInt(); * long largeFileSize = in_.readLong(); * in_.skipBytes(2); * int symlink = in_.readByte(); // 91 */ in_.skipBytes(70); numRead = 92; int fileNameLLOffset = 20 + templateLength; int toSkip = fileNameLLOffset - numRead; in_.skipBytes(toSkip); numRead += toSkip; int fileNameLength = in_.readInt() - 6; in_.skipBytes(2); // 0x0002 -- Name CP. numRead += 6; sbyte[] nameBuf = new sbyte[fileNameLength]; in_.readFully(nameBuf); numRead += fileNameLength; string name = Conv.unicodeByteArrayToString(nameBuf, 0, nameBuf.Length); if (!name.Equals(".") && !name.Equals("..")) { files.Add(name); } int remaining = length - numRead; in_.skipBytes(remaining); } else { int remaining = length - 22; in_.skipBytes(remaining); throw DataStreamException.badReply("listFiles", reqRepID); } } return(files); }
/// <summary> /// Returns a list of files under the specified directory or file spec. /// For example, these all return the same file listing: /// <ul> /// <li>list("/home/smith")</li> /// <li>list("/home/smith/*")</li> /// <li>list("/home/smith/../smith")</li> /// </ul> /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public java.util.List<FileHandle> listFiles(String dir) throws IOException public virtual IList <FileHandle> listFiles(string dir) { if (dir.IndexOf("*", StringComparison.Ordinal) < 0) { if (!dir.EndsWith("/", StringComparison.Ordinal)) { dir = dir + "/*"; } else { dir = dir + "*"; } } string parent = dir; int slash = parent.LastIndexOf("/", StringComparison.Ordinal); if (slash < 0) { parent = ""; } else if (slash > 0) { parent = parent.Substring(0, slash + 1); } sendListFilesRequest(Conv.stringToUnicodeByteArray(dir)); out_.flush(); List <FileHandle> files = new List <FileHandle>(); int chain = 1; while (chain != 0) { int length = in_.readInt(); if (length < 24) { throw DataStreamException.badLength("listFiles", length); } int headerID = in_.readShort(); int serverID = in_.readShort(); int csInstance = in_.readInt(); int correlationID = in_.readInt(); int templateLength = in_.readShort(); int reqRepID = in_.readShort(); chain = in_.readShort(); if (reqRepID == 0x8001) { int rc = in_.readShort(); int remaining = length - 24; in_.skipBytes(remaining); if (rc != FileConstants.RC_NO_MORE_FILES) { throw DataStreamException.badReturnCode("listFiles", rc); } } else if (reqRepID == 0x8005) { int numRead = 22; long createDate = convertDate(in_); long modifyDate = convertDate(in_); long accessDate = convertDate(in_); int fileSize = in_.readInt(); int fixedAttributes = in_.readInt(); int objectType = in_.readShort(); int numExtAttrs = in_.readShort(); int bytesEANames = in_.readInt(); int bytesEAValues = in_.readInt(); int version = in_.readInt(); int amountAccessed = in_.readShort(); int accessHistory = in_.readByte(); int fileCCSID = in_.readShort(); int checkoutCCSID = in_.readShort(); int restartID = in_.readInt(); long largeFileSize = in_.readLong(); in_.skipBytes(2); int symlink = in_.readByte(); // 91 numRead = 92; int fileNameLLOffset = 20 + templateLength; int toSkip = fileNameLLOffset - numRead; in_.skipBytes(toSkip); numRead += toSkip; int fileNameLength = in_.readInt() - 6; in_.skipBytes(2); // 0x0002 -- Name CP. numRead += 6; sbyte[] nameBuf = new sbyte[fileNameLength]; in_.readFully(nameBuf); numRead += fileNameLength; string name = Conv.unicodeByteArrayToString(nameBuf, 0, nameBuf.Length); if (!name.Equals(".") && !name.Equals("..")) { FileHandle h = FileHandle.createEmptyHandle(); h.Name = name; h.Path = parent + name; h.DataCCSID = fileCCSID; h.CreateDate = createDate; h.ModifyDate = modifyDate; h.AccessDate = accessDate; h.Size = largeFileSize; h.Version = version; h.Symlink = symlink == 1; h.Directory = objectType == 2; files.Add(h); } int remaining = length - numRead; in_.skipBytes(remaining); } else { int remaining = length - 22; in_.skipBytes(remaining); throw DataStreamException.badReply("listFiles", reqRepID); } } return(files); }
/// <summary> /// Connects to the Remote Command host server on the specified port using the specified system information and user. /// /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static CommandConnection getConnection(final boolean isSSL, SystemInfo info, String user, String password, int commandPort, boolean compress) throws IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public static CommandConnection getConnection(bool isSSL, SystemInfo info, string user, string password, int commandPort, bool compress) { if (commandPort < 0 || commandPort > 65535) { throw new IOException("Bad command port: " + commandPort); } CommandConnection conn = null; Socket commandServer = isSSL? SSLSocketFactory.Default.createSocket(info.System, commandPort) : new Socket(info.System, commandPort); Stream @in = commandServer.InputStream; Stream @out = commandServer.OutputStream; try { if (compress) { throw new IOException("Experimental compression streams not enabled."); // in = new CompressionInputStream(in); // out = new CompressionOutputStream(new BufferedOutputStream(out)); } // Exchange random seeds. HostOutputStream dout = new HostOutputStream(compress ? @out : new BufferedOutputStream(@out)); HostInputStream din = new HostInputStream(new BufferedInputStream(@in)); string jobName = connect(info, dout, din, 0xE008, user, password); string NLV = Conv.DefaultNLV; sendExchangeAttributesRequest(dout, NLV); dout.flush(); int length = din.readInt(); if (length < 20) { throw DataStreamException.badLength("commandExchangeAttributes", length); } din.skipBytes(16); int rc = din.readShort(); // We ignore the same return codes that JTOPEN ignores if (rc != 0x0100 && rc != 0x0104 && rc != 0x0105 && rc != 0x0106 && rc != 0x0107 && rc != 0x0108 && rc != 0) { throw DataStreamException.badReturnCode("commandExchangeAttributes", rc); } int ccsid = din.readInt(); sbyte[] nlvBytes = new sbyte[4]; nlvBytes[0] = (sbyte)din.readByte(); nlvBytes[1] = (sbyte)din.readByte(); nlvBytes[2] = (sbyte)din.readByte(); nlvBytes[3] = (sbyte)din.readByte(); NLV = Conv.ebcdicByteArrayToString(nlvBytes, 0, 4); // Server version din.skipBytes(4); int datastreamLevel = din.readShort(); din.skipBytes(length - 36); din.end(); conn = new CommandConnection(info, commandServer, din, dout, ccsid, datastreamLevel, user, jobName, NLV); return(conn); } finally { if (conn == null) { @in.Close(); @out.Close(); commandServer.close(); } } }