protected override async Task<string> OnProcess(string sMessage)
		{
			string sFile = GetPath(sMessage);

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

			if (file == null)
			{
				return await GetMessage(425, "Couldn't open file");
			}
			
			FtpReplySocket socketReply = new FtpReplySocket(ConnectionObject);

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

			byte [] abData = new byte[m_nBufferSize];

			await Assemblies.General.SocketHelpers.Send(ConnectionObject.Socket, await 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 await GetMessage(226, string.Format("Appended file successfully. ({0})", sFile));
		}
        protected override async Task<string> OnProcess(string sMessage)
		{
			string sFilePath = GetPath(sMessage);
			
			if (!ConnectionObject.FileSystemObject.FileExists(sFilePath))
			{
				return await GetMessage(550, "File doesn't exist");
			}

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

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

			const int m_nBufferSize = 65536;

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

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

			byte [] abBuffer = new byte[m_nBufferSize];

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

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

			file.Close();			
			replySocket.Close();
					
			return await GetMessage(226, "File download succeeded.");
		}
        protected override string OnProcess(string sMessage)
        {
            string sFilePath = this.GetPath(sMessage);

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

            var replySocket = new FtpReplySocket(this.ConnectionObject);

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

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

            const int bufferSize = 65536;

            IFile file = this.ConnectionObject.FileSystemObject.OpenFile(sFilePath, false);
            if (file == null)
            {
                return this.GetMessage(550, "Couldn't open file");
            }

            var abBuffer = new byte[bufferSize];

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

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

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

            return this.GetMessage(226, "File download succeeded.");
        }
        protected override string OnProcess(string message)
        {
            SocketHelpers.Send(this.ConnectionObject.Socket, "150 Opening data connection for LIST\r\n");

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

            message = message.Trim();

            string path = this.GetPath(string.Empty);

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

            var    asAll    = ArrayHelpers.Add(asDirectories, asFiles) as string[];
            string fileList = this.BuildReply(message, asAll);

            var socketReply = new FtpReplySocket(this.ConnectionObject);

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

            socketReply.Send(fileList);
            socketReply.Close();

            return(this.GetMessage(226, "LIST successful."));
        }
        protected override async Task<string> OnProcess(string sMessage)
		{
			await Assemblies.General.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 [] asAll = Assemblies.General.ArrayHelpers.Add(asDirectories, asFiles) as string[];
			string sFileList = BuildReply(sMessage, asAll);
			
			FtpReplySocket socketReply = new FtpReplySocket(ConnectionObject);

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

			return await GetMessage(226, "LIST successful.");
		}
Beispiel #6
0
        protected override string OnProcess(string sMessage)
        {
            Assemblies.General.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 [] asAll     = Assemblies.General.ArrayHelpers.Add(asDirectories, asFiles) as string[];
            string    sFileList = BuildReply(sMessage, asAll);

            FtpReplySocket 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."));
        }
        protected override string OnProcess(string message)
        {
            SocketHelpers.Send(this.ConnectionObject.Socket, "150 Opening data connection for LIST\r\n");

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

            message = message.Trim();

            string path = this.GetPath("");

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

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

            var socketReply = new FtpReplySocket(this.ConnectionObject);

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

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

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