Exemplo n.º 1
0
        public string SendCommand(string cmd)
        {
            IntPtr ftpCommand = new IntPtr();
            int    num        = (cmd != "PASV") ? WININET.FtpCommand(_hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand) : WININET.FtpCommand(_hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand);
            int    capacity   = 0x2000;

            if (num == 0)
            {
                Error();
            }
            else if (ftpCommand != IntPtr.Zero)
            {
                StringBuilder buffer    = new StringBuilder(capacity);
                int           bytesRead = 0;
                while (true)
                {
                    num = WININET.InternetReadFile(ftpCommand, buffer, capacity, ref bytesRead);
                    if ((num != 1) || (bytesRead <= 1))
                    {
                        return(buffer.ToString());
                    }
                }
            }
            return("");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a command to the FTP server
        /// </summary>
        /// <param name="cmd">A <see cref="String"/> representing the command to send.</param>
        /// <returns>A <see cref="String"/> containing the server response.</returns>
        public string SendCommand(string cmd)
        {
            int    result;
            IntPtr dataSocket = new IntPtr();

            switch (cmd)
            {
            case "PASV":
                result = WININET.FtpCommand(_hConnect, false, WININET.FTP_TRANSFER_TYPE_ASCII, cmd, IntPtr.Zero, ref dataSocket);
                break;

            default:
                result = WININET.FtpCommand(_hConnect, false, WININET.FTP_TRANSFER_TYPE_ASCII, cmd, IntPtr.Zero, ref dataSocket);
                break;
            }

            int BUFFER_SIZE = 8192;

            if (result == 0)
            {
                Error();
            }
            else if (dataSocket != IntPtr.Zero)
            {
                StringBuilder buffer    = new StringBuilder(BUFFER_SIZE);
                int           bytesRead = 0;

                do
                {
                    result = WININET.InternetReadFile(dataSocket, buffer, BUFFER_SIZE, ref bytesRead);
                } while (result == 1 && bytesRead > 1);

                return(buffer.ToString());
            }

            return("");
        }
Exemplo n.º 3
0
        public string SendCommand(string cmd)
        {
            IntPtr ftpCommand = new();
            int    num        = cmd != "PASV"
                ? WININET.FtpCommand(_hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand)
                : WININET.FtpCommand(_hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand);
            int capacity = 0x2000;

            switch (num)
            {
            case 0:
                Error();
                break;

            default:
            {
                if (ftpCommand != IntPtr.Zero)
                {
                    StringBuilder buffer    = new(capacity);
                    int           bytesRead = 0;
                    while (true)
                    {
                        num = WININET.InternetReadFile(ftpCommand, buffer, capacity, ref bytesRead);
                        if (num != 1 || bytesRead <= 1)
                        {
                            return(buffer.ToString());
                        }
                    }
                }

                break;
            }
            }

            return("");
        }