Esempio n. 1
0
        protected override string OnProcess(string sMessage)
        {
            string sFile = GetPath(sMessage);

            if (ConnectionObject.FileSystemObject.FileExists(sFile))
            {
                return GetMessage(553, "File already exists.");
            }

            FtpFile file = ConnectionObject.FileSystemObject.OpenFile(sFile, true);

            var socketReply = new FtpReplySocket(ConnectionObject);

            if (!socketReply.Loaded)
            {
                return GetMessage(425, "Error in establishing data connection.");
            }

            var abData = new byte[nBufferSize];

            Send(GetMessage(150, "Opening connection for data transfer."));

            int nReceived = socketReply.Receive(abData);

            while (nReceived > 0)
            {
                file.Write(abData, nReceived);
                nReceived = socketReply.Receive(abData);
            }

            file.Close();
            socketReply.Close();

            return GetMessage(226, "Uploaded file successfully.");
        }
Esempio n. 2
0
        protected override string OnProcess(string sMessage)
        {
            string sFile = GetPath(sMessage);

            FtpFile file = ConnectionObject.FileSystemObject.OpenFile(sFile, true);

            if (file == null)
            {
                return GetMessage(425, "Couldn't open file");
            }

            var socketReply = new FtpReplySocket(ConnectionObject);

            if (!socketReply.Loaded)
            {
                return GetMessage(425, "Error in establishing data connection.");
            }

            var abData = new byte[nBufferSize];

            Send(GetMessage(150, "Opening connection for data transfer."));

            int nReceived = socketReply.Receive(abData);

            while (nReceived > 0)
            {
                nReceived = socketReply.Receive(abData);
                file.Write(abData, nReceived);
            }

            file.Close();
            socketReply.Close();

            return GetMessage(226, string.Format("Appended file successfully. ({0})", sFile));
        }
Esempio n. 3
0
        protected override string OnProcess(string sMessage)
        {
            string sFilePath = GetPath(sMessage);

            if (!ConnectionObject.FileSystemObject.FileExists(sFilePath))
            {
                return GetMessage(550, "File doesn't exist");
            }

            var replySocket = new FtpReplySocket(ConnectionObject);

            if (!replySocket.Loaded)
            {
                return GetMessage(550, "Unable to establish data connection");
            }

            Send("150 Starting data transfer, please wait...\r\n");

            const int bufferSize = 65536;

            FtpFile file = ConnectionObject.FileSystemObject.OpenFile(sFilePath, false);

            if (file == null)
            {
                return GetMessage(550, "Couldn't open file");
            }

            var byteBuffer = new byte[bufferSize];

            int read = file.Read(byteBuffer, bufferSize);

            try
            {
                while (read > 0)
                {
                    replySocket.Send(byteBuffer, read);
                    read = file.Read(byteBuffer, bufferSize);
                }

                return GetMessage(226, "File download succeeded.");
            }
            finally
            {
                file.Close();
                replySocket.Close();
            }
        }
Esempio n. 4
0
        protected override string OnProcess(string sMessage)
        {
            Send("150 Opening data connection for LIST\r\n");

            string[] asFiles = null;
            string[] asDirectories = null;

            sMessage = sMessage.Trim();

            string sPath = GetPath("");

            if (sMessage.Length == 0 || sMessage[0] == '-')
            {
                asFiles = ConnectionObject.FileSystemObject.GetFiles(sPath);
                asDirectories = ConnectionObject.FileSystemObject.GetDirectories(sPath);
            }
            else
            {
                asFiles = ConnectionObject.FileSystemObject.GetFiles(sPath, sMessage);
                asDirectories = ConnectionObject.FileSystemObject.GetDirectories(sPath, sMessage);
            }

            var asAll = ArrayHelpers.Add(asDirectories, asFiles) as string[];
            string sFileList = BuildReply(sMessage, asAll);

            var socketReply = new FtpReplySocket(ConnectionObject);

            if (!socketReply.Loaded)
            {
                return GetMessage(550, "LIST unable to establish return connection.");
            }

            try
            {
                socketReply.Send(sFileList, ConnectionObject.Id);
                return GetMessage(226, "LIST successful.");
            }
            finally
            {
                socketReply.Close();
            }
        }