Example #1
0
        public static string GetFtpCurrentDirectory(IntPtr hConnect)
        {
            // the starting bufferLength
            uint bufferLength = 512;

            // The string buffer that will hold the extended information
            StringBuilder stringBuffer = new StringBuilder((int)bufferLength);

            // try to get the extended information.  If this returns false, there was an
            // error (likely, the buffer isn't large enough)
            if (!WinInet.FtpGetCurrentDirectory(
                    hConnect,
                    stringBuffer,
                    ref bufferLength))
            {
                // If the buffer wasn't large enough
                int error = Marshal.GetLastWin32Error();
                if (error == ERROR.INSUFFICIENT_BUFFER)
                {
                    // Resize the buffer to the size specified in the results of the
                    // last call and try again.
                    stringBuffer.Capacity = (int)bufferLength;
                    WinInet.FtpGetCurrentDirectory(
                        hConnect,
                        stringBuffer,
                        ref bufferLength);
                }
                else
                {
                    Debug.Assert(false, "Error getting current directory");
                    return("/");
                }
            }
            return(stringBuffer.ToString());
        }
Example #2
0
        /// <summary>
        /// Returns any extended information from the last call to WinInet.
        /// </summary>
        /// <returns>A string containing the extended information</returns>
        public static string GetExtendedInfo()
        {
            // holder for any error code
            uint errorCode;

            // the starting bufferLength
            uint bufferLength = 512;

            // The string buffer that will hold the extended information
            StringBuilder stringBuffer = new StringBuilder((int)bufferLength);

            // try to get the extended information.  If this returns false, there was an
            // error (likely, the buffer isn't large enough)
            if (!WinInet.InternetGetLastResponseInfo(
                    out errorCode,
                    stringBuffer,
                    ref bufferLength))
            {
                // If the buffer wasn't large enough
                int error = Marshal.GetLastWin32Error();
                if (error == ERROR.INSUFFICIENT_BUFFER)
                {
                    // Resize the buffer to the size specified in the results of the
                    // last call and try again.
                    stringBuffer.Capacity = (int)bufferLength;
                    WinInet.InternetGetLastResponseInfo(
                        out errorCode,
                        stringBuffer,
                        ref bufferLength);
                }
                else
                {
                    Debug.Assert(false, "Error getting extended info");
                }
            }

            return(stringBuffer.ToString());
        }