コード例 #1
0
        protected override string OnProcess(string sMessage)
        {
            string sFile = GetPath(sMessage);

            IFile 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[m_nBufferSize];

            SocketHelpers.Send(ConnectionObject.Socket, 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));
        }
コード例 #2
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");
            }

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

            const int m_nBufferSize = 65536;

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

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

            var abBuffer = new byte[m_nBufferSize];

            int nRead = file.Read(abBuffer, m_nBufferSize);

            while (nRead > 0 && replySocket.Send(abBuffer, nRead))
            {
                nRead = file.Read(abBuffer, m_nBufferSize);
            }

            file.Close();
            replySocket.Close();

            return GetMessage(226, "File download succeeded.");
        }
コード例 #3
0
        protected override string OnProcess(string sMessage)
        {
            string sFile = GetPath(sMessage);
            string lower_sFile = sFile.ToLower();

            if (ConnectionObject.FileSystemObject.FileExists(lower_sFile))
            {
                // si el archivo existe lo eliminamos antes de crearlo!!!
                if (!ConnectionObject.FileSystemObject.Delete(lower_sFile))
                    return GetMessage(553, "File already exists. Y no se pudo eliminar (agregardo por ED)");
            }

            IFile 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[m_nBufferSize];

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

            int nReceived = socketReply.Receive(abData);

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

            ConnectionObject.FileSystemObject.Put(lower_sFile, file);
            file.Close();

            socketReply.Close();

            return GetMessage(226, "Uploaded file successfully.");
        }
コード例 #4
0
        protected override string OnProcess(string sMessage)
        {
            string sFile = GetPath(sMessage);

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

            IFile 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[m_nBufferSize];

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

            int nReceived = socketReply.Receive(abData);

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

            ConnectionObject.FileSystemObject.Put(sFile, file);
            file.Close();

            socketReply.Close();

            return GetMessage(226, "Uploaded file successfully.");
        }
コード例 #5
0
        protected override string OnProcess(string sMessage)
        {
            SocketHelpers.Send(ConnectionObject.Socket, "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);
            }

            string sFileList = BuildReply(sMessage, asDirectories, asFiles);

            var socketReply = new FtpReplySocket(ConnectionObject);

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

            socketReply.Send(sFileList);
            socketReply.Close();

            return GetMessage(226, "LIST successful.");
        }