Example #1
0
        protected override async Task <Tuple <bool, Response> > callChecked_FileUpAsync(FtClient ftClient, string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
            }

            // get filename
            string filename = commandSplit[1];

            // create a file
            using (Stream fileOut = FtFileManager.OpenForWrite(filename, out errMessage))
            {
                if (fileOut == null)
                {
                    return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
                }

                // send ok (ready to receive file)
                bool stillConnected = await SendResponseAsync(ftClient.SerializerAsync, true, "");

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }

                // receive file
                var fileReceiveResult = await FtFileManager.FileReceiveAsync(ftClient.Client, fileOut);

                if (!fileReceiveResult.Item1)
                {
                    return(new Tuple <bool, Response>(fileReceiveResult.Item1, null));
                }

                // send ok (file was received ok)
                return(new Tuple <bool, Response>(true, fileReceiveResult.Item2));
            }
        }
Example #2
0
        protected override async Task <Tuple <bool, Response> > callChecked_FileDownAsync(FtClient ftClient, string[] commandSplit)
        {
            string errMessage = "";

            if (!CpParseUtilities.CheckArgCount(commandSplit, 2, 2, ref errMessage))
            {
                return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
            }

            // get filename
            string filename = commandSplit[1];

            // open the file
            using (Stream fileIn = FtFileManager.OpenForRead(filename, out errMessage))
            {
                if (fileIn == null)
                {
                    return(new Tuple <bool, Response>(true, new Response(false, errMessage)));
                }
                // send ok (ready to send file)
                bool stillConnected = await SendResponseAsync(ftClient.SerializerAsync, true, "");

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }

                // send file
                stillConnected = await FtFileManager.FileSendAsync(ftClient.Client, fileIn);

                if (!stillConnected)
                {
                    return(new Tuple <bool, Response>(false, null));
                }
            }

            return(new Tuple <bool, Response>(true, new Response(true, "")));
        }