コード例 #1
0
        /// <summary>
        /// Creates a directory structure recursively given a path
        /// </summary>
        /// <param name="directories"></param>
        /// <param name="isRootedPath"></param>
        /// <returns></returns>
        private async Task CreateDirectoryStructureRecursively(IEnumerable <string> directories, bool isRootedPath)
        {
            LoggerHelper.Debug($"[FtpClient] Creating directory structure recursively {string.Join("/", directories)}");
            string originalPath = WorkingDirectory;

            if (isRootedPath && directories.Any())
            {
                await ChangeWorkingDirectoryAsync("/");
            }

            if (!directories.Any())
            {
                return;
            }

            if (directories.Count() == 1)
            {
                await ControlStream.SendCommandAsync(new FtpCommandEnvelope
                {
                    FtpCommand = FtpCommand.MKD,
                    Data       = directories.First()
                });

                await ChangeWorkingDirectoryAsync(originalPath);

                return;
            }

            foreach (string directory in directories)
            {
                if (directory.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var response = await ControlStream.SendCommandAsync(new FtpCommandEnvelope
                {
                    FtpCommand = FtpCommand.CWD,
                    Data       = directory
                });

                if (response.FtpStatusCode != FtpStatusCode.ActionNotTakenFileUnavailable)
                {
                    continue;
                }

                await ControlStream.SendCommandAsync(new FtpCommandEnvelope
                {
                    FtpCommand = FtpCommand.MKD,
                    Data       = directory
                });

                await ControlStream.SendCommandAsync(new FtpCommandEnvelope
                {
                    FtpCommand = FtpCommand.CWD,
                    Data       = directory
                });
            }

            await ChangeWorkingDirectoryAsync(originalPath);
        }
コード例 #2
0
        /// <summary>
        /// Provides a stream which contains the data of the given filename on the FTP server
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task <Stream> OpenFileReadStreamAsync(string fileName)
        {
            LoggerHelper.Debug($"[FtpClient] Opening file read stream for {fileName}");

            return(new FtpDataStream(await OpenFileStreamAsync(fileName, FtpCommand.RETR), this));
        }