Exemplo n.º 1
0
        /// <summary>
        /// Deletes the specified file.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int deleteFile(String filename) throws IOException
        public virtual int deleteFile(string filename)
        {
            sendDeleteFileRequest(out_, Conv.stringToUnicodeByteArray(filename));
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("deleteFile", 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();

            in_.skipBytes(2);
            if (reqRepID == 0x8001)
            {
                int rc        = in_.readShort();
                int remaining = length - 24;
                in_.skipBytes(remaining);
                return(rc);
            }
            else
            {
                int remaining = length - 22;
                in_.skipBytes(remaining);
                throw DataStreamException.badReply("deleteFile", reqRepID);
            }
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calls the specified program and returns the result.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public CommandResult call(Program pgm) throws IOException
        public virtual CommandResult call(Program pgm)
        {
            if (Closed)
            {
                throw new IOException("Connection closed");
            }

            pgm.newCall();

            sendCallProgramRequest(out_, pgm, datastreamLevel_);
            out_.flush();

            int length = in_.readInt();

            if (length < 20)
            {
                throw DataStreamException.badLength("commandCallProgram", length);
            }
            in_.skipBytes(16);
            int rc = in_.readShort();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean success = rc == 0;
            bool success = rc == 0;

            Message[] messages = null;
            if (rc == 0)
            {
                in_.skipBytes(2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int numParms = pgm.getNumberOfParameters();
                int numParms = pgm.NumberOfParameters;
                for (int i = 0; i < numParms; ++i)
                {
                    if (pgm.getParameterOutputLength(i) > 0)
                    {
                        int byteLength = in_.readInt();
                        in_.skipBytes(2);
                        int     outputLength = in_.readInt();
                        int     usage        = in_.readShort();
                        int     parmLength   = byteLength - 12;
                        sbyte[] buf          = pgm.TempDataBuffer;
                        if (buf == null || buf.Length < parmLength)
                        {
                            buf = new sbyte[parmLength];
                        }
                        in_.readFully(buf, 0, parmLength);
                        pgm.setParameterOutputData(i, buf, parmLength);
                    }
                }
                messages = new Message[0];
            }
            else
            {
                messages = getMessages(length);
                //      throw DataStreamException.badReturnCode("commandCallProgram", rc);
            }
            in_.end();
            return(new CommandResult(success, messages, rc));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int readFile(FileHandle handle, byte[] buffer, int bufferOffset, int bufferLength) throws IOException
        public virtual int readFile(FileHandle handle, sbyte[] buffer, int bufferOffset, int bufferLength)
        {
            long currentOffset = handle.Offset;

            sendReadRequest(handle.Handle, currentOffset, bufferLength);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("readFile", 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();
            int chain          = in_.readShort(); //in_.skipBytes(2);
            int numRead        = 22;
            int remaining      = length - 22;
            int rc             = 0;
            int numToRead      = -1;

            if (reqRepID == 0x8001)
            {
                rc         = in_.readShort();
                remaining -= 2;
                numRead   += 2;
            }
            else if (reqRepID == 0x8003)
            {
                int ccsid      = in_.readShort();
                int dataLength = in_.readInt();
                in_.skipBytes(2);
                remaining -= 8;
                int numBytes = dataLength - 6;
                numToRead = numBytes > length ? length : numBytes;
                int numToSkip = numToRead >= numBytes ? 0 : numBytes - length;
                in_.readFully(buffer, bufferOffset, numToRead);
                in_.skipBytes(numToSkip);
                handle.Offset = currentOffset + numToRead;
                remaining    -= numBytes;
                numRead      += 6;
                numRead      += numToRead;
                numRead      += numToSkip;
            }
            else
            {
                in_.skipBytes(remaining);
                numRead += remaining;
                throw DataStreamException.badReply("readFile", reqRepID);
            }
            in_.skipBytes(remaining - 2);
            handle.LastStatus = rc;
            return(numToRead);
        }
Exemplo n.º 5
0
//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();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calls the specified program using the specified parameter data and returns the result.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public CommandResult call(String pgmLibrary, String pgmName, Parameter[] parms) throws IOException
        public virtual CommandResult call(string pgmLibrary, string pgmName, Parameter[] parms)
        {
            if (Closed)
            {
                throw new IOException("Connection closed");
            }

            sendCallProgramRequest(out_, pgmLibrary, pgmName, parms, datastreamLevel_);
            out_.flush();

            int length = in_.readInt();

            if (length < 20)
            {
                throw DataStreamException.badLength("commandCallProgram", length);
            }
            in_.skipBytes(16);
            int rc = in_.readShort();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean success = rc == 0;
            bool success = rc == 0;

            Message[] messages = null;
            if (rc == 0)
            {
                in_.skipBytes(2);
                for (int i = 0; i < parms.Length; ++i)
                {
                    if (parms[i].OutputLength > 0)
                    {
                        int byteLength = in_.readInt();
                        in_.skipBytes(2);
                        int     outputLength = in_.readInt();
                        int     usage        = in_.readShort();
                        sbyte[] outputData   = new sbyte[byteLength - 12];
                        in_.readFully(outputData);
                        parms[i].OutputData = outputData;
                    }
                }
                messages = new Message[0];
            }
            else
            {
                messages = getMessages(length);
                //      throw DataStreamException.badReturnCode("commandCallProgram", rc);
            }
            in_.end();
            return(new CommandResult(success, messages, rc));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes data to the file starting at the current file offset in the handle, and optionally sync-ing the data to disk;
        /// upon a successful write, the current file offset and size are incremented.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeFile(FileHandle handle, byte[] buffer, int bufferOffset, int bufferLength, boolean sync) throws IOException
        public virtual void writeFile(FileHandle handle, sbyte[] buffer, int bufferOffset, int bufferLength, bool sync)
        {
            long currentOffset = handle.Offset;

            sendWriteRequest(handle.Handle, currentOffset, buffer, bufferOffset, bufferLength, handle.DataCCSID, sync);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("writeFile", 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();
            int chain          = in_.readShort(); //in_.skipBytes(2);
            int numRead        = 22;
            int rc             = 0;

            if (reqRepID == 0x8001)
            {
                rc       = in_.readShort();
                numRead += 2;
            }
            else if (reqRepID == 0x800B)
            {
                rc = in_.readShort();
                int previousFileSize = in_.readInt();
                int bytesNotWritten  = in_.readInt();
                numRead      += 10;
                handle.Offset = currentOffset + (bufferLength - bytesNotWritten);
                handle.Size   = handle.Size + (bufferLength - bytesNotWritten);
            }
            else
            {
                in_.skipBytes(length - numRead);
                numRead = length;
                throw DataStreamException.badReply("writeFile", reqRepID);
            }
            in_.skipBytes(length - numRead);
            handle.LastStatus = rc;
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int closeFile(FileHandle handle) throws IOException
        public virtual int closeFile(FileHandle handle)
        {
            if (!handle.Open)
            {
                // Someone is trying to close an already-closed handle!
                //TODO
                return(-1);
            }
            sendCloseFileRequest(handle.Handle);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("closeFile", 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();

            in_.skipBytes(2);
            int remaining = length - 22;

            if (reqRepID == 0x8001 || reqRepID == 0x8004)
            {
                int rc = in_.readShort();
                in_.skipBytes(remaining - 2);
                return(rc);
            }
            else
            {
                in_.skipBytes(remaining);
                throw DataStreamException.badReply("closeFile", reqRepID);
            }
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int openFile(String filename, FileHandle buffer, int openType, int shareOption, boolean createIfNotExist, int dataCCSID) throws IOException
        public virtual int openFile(string filename, FileHandle buffer, int openType, int shareOption, bool createIfNotExist, int dataCCSID)
        {
            if (buffer.Open)
            {
                // Someone is re-using their buffer without closing the file!
                //TODO closeFile(buffer);
            }
            sendOpenFileRequest(Conv.stringToUnicodeByteArray(filename), openType, shareOption, createIfNotExist, dataCCSID);
            out_.flush();

            int length = in_.readInt();

            if (length < 24)
            {
                throw DataStreamException.badLength("openFile", 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();

            in_.skipBytes(2);
            int remaining = length - 22;
            int rc        = 0;

            if (reqRepID == 0x8001)
            {
                rc         = in_.readShort();
                remaining -= 2;
            }
            else if (reqRepID == 0x8002)
            {
                int  handle = in_.readInt();
                long id     = in_.readLong();
                dataCCSID = in_.readShort();
                int  actionTaken           = in_.readShort();
                long createDate            = convertDate(in_);
                long modifyDate            = convertDate(in_);
                long accessDate            = convertDate(in_);
                int  fileSize              = in_.readInt();
                long actualFileSize        = fileSize;
                int  fixedAttribs          = in_.readInt();
                int  needExtAttribs        = in_.readShort();
                int  numExtAttribs         = in_.readShort();
                int  charsExtAttribsNames  = in_.readInt();
                int  bytesExtAttribsValues = in_.readInt();
                int  version        = in_.readInt();
                int  amountAccessed = in_.readShort();
                int  accessHistory  = in_.readByte();
                remaining -= 67;
                if (length >= 97)
                {
                    long largeFileSize = in_.readLong();
                    remaining     -= 8;
                    actualFileSize = largeFileSize;
                }
                buffer.Open       = true;
                buffer.OpenType   = openType;
                buffer.Name       = filename;
                buffer.Handle     = handle;
                buffer.ID         = id;
                buffer.DataCCSID  = dataCCSID;
                buffer.CreateDate = createDate;
                buffer.ModifyDate = modifyDate;
                buffer.AccessDate = accessDate;
                buffer.Size       = actualFileSize;
                buffer.Version    = version;
            }
            else
            {
                in_.skipBytes(remaining);
                throw DataStreamException.badReply("openFile", reqRepID);
            }
            in_.skipBytes(remaining - 2);
            return(rc);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        /// <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();
                }
            }
        }