Esempio n. 1
0
        /// <summary>
        /// Get the full directory details of the current directory.
        /// </summary>
        /// <param name="remoteDirectory">The remove directory, emtpy or <c>null</c> will get the details of the current directory.</param>
        /// <returns>A array that contains all the FTP files located in the currenct directory.</returns>
        public FtpEntry[] GetDirectoryDetails(String remoteDirectory)
        {
            String listCommand = "LIST";

            if (!String.IsNullOrEmpty(remoteDirectory))
            {
                listCommand += " " + remoteDirectory;
            }

            using (Stream stream = CreateDataStreamAndSendCommand(listCommand))
            {
                byte[] buffer        = new byte[8192];
                int    bytesReceived = stream.Read(buffer, 0, buffer.Length);
                String dirEntryList  = String.Empty;

                while (bytesReceived > 0)
                {
                    dirEntryList += ConversationEncoding.GetString(buffer, 0, bytesReceived);
                    bytesReceived = stream.Read(buffer, 0, buffer.Length);
                }

                String[] dirEntries = dirEntryList.Split('\n');
                return(FtpEntry.ParseDirList(dirEntries));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the response string from the client socket.
        /// </summary>
        /// <returns>The response of the client socket.</returns>
        private String ReadResponseString()
        {
            Byte[] buffer         = new Byte[8192];
            String responseString = String.Empty;

            int bytesReceived = ClientSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None);

            while (bytesReceived > 0)
            {
                responseString += ConversationEncoding.GetString(buffer, 0, bytesReceived);

                if (bytesReceived == buffer.Length)
                {
                    bytesReceived = ClientSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
                }
                else
                {
                    break;
                }
            }

            if (LogFtpMessageConversation)
            {
                Log.LogMessage(MessageImportance.Low, "FTP < {0}", responseString.Trim('\n', '\r'));
            }

            return(responseString);
        }
Esempio n. 3
0
        /// <summary>
        /// Send a command to the FTP server.
        /// </summary>
        /// <param name="rawCommand">The full command to send.</param>
        protected void SendCommand(String rawCommand)
        {
            // Add \r\n to command if it doesn't contain it.
            if (!rawCommand.EndsWith(Environment.NewLine))
            {
                rawCommand = String.Concat(rawCommand, Environment.NewLine);
            }

            // Get byte representation of the command and send it.
            Byte[] buffer = ConversationEncoding.GetBytes(rawCommand);
            ClientSocket.Send(buffer);

            if (LogFtpMessageConversation)
            {
                // Log conversation.
                Log.LogMessage(MessageImportance.Low, "FTP > {0}", rawCommand.Trim('\n', '\r'));
            }
        }