예제 #1
0
        private async Task <IFtpWebResponse> InvokeFtpRequest(string method, string path, bool usePassive = false, byte[] requestData = null)
        {
            if (!path.StartsWith("/"))
            {
                path = $"/{path}";
            }

            var ftpRequest = FtpWebRequestFactory.Create($"ftp://{Host}{path}");

            ftpRequest.Credentials = new NetworkCredential(UserName, Password);
            ftpRequest.Method      = method;
            ftpRequest.UsePassive  = usePassive;
            ftpRequest.EnableSsl   = UseSsl;

            if (requestData == null)
            {
                return(await ftpRequest.GetResponse());
            }

            ftpRequest.ContentLength = requestData.Length;

            using var writer = await ftpRequest.GetRequestStream();

            writer.Write(requestData, 0, requestData.Length);

            return(await ftpRequest.GetResponse());
        }
예제 #2
0
        public void FtpWebRequestFactoryTestCreate_WebException()
        {
            var factory = new FtpWebRequestFactory();

            var test = factory.Create("ftp://*****:*****@404.nl");

            test.GetResponse();
        }