FtpWebRequest request =(FtpWebRequest)WebRequest.Create(uri);例外

时间:2019-11-07 22:27:36

标签: c# ftpwebrequest ftps

我尝试连接到服务器ftps://waws-XXXXXXXXXXXX.windows.net并上传文件 但是使用时我有一些问题

var reqCakes = (FtpWebRequest)WebRequest.Create("ftps://waws-prod-sn1-145.ftp.azurewebsites.windows.net");

此行引发以下异常:

  

无法识别URI前缀

当我使用

var reqCakes = (FtpWebRequest)WebRequest.Create("ftp://waws-prod-sn1-145.ftp.azurewebsites.windows.net");

线

Stream reqStream = reqCakes.GetRequestStream();

向我抛出以下异常:

  

请求的URI对于此FTP命令无效。

有人知道为什么会发生这种情况吗,我该如何解决?

这是完整的代码,我查看了所有文档,但没有发现错误所在

namespace Storages
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                //---------FTPS-----------------------------------------------------
                var Hostname = "ftps://waws-prod-sn1-145.ftp.azurewebsites.windows.net";
                var Username = @"apifonacotboxv2\usuarioi-FTP";
                var Password = "WebDeploy1$";
                var hostDirectory = @"\site\wwwroot";

                var localDirectory = @"C:\Users\Usuario\Documents\";
                var continer = "8025fbb8-07fd-448a-a77d-91ec76619505";
                var fileName = "64fde761-1ab6-41a3-aab1-249f98e7c328.docx";
                var FromPath = Path.Combine(localDirectory, continer, fileName);
                byte[] b = File.ReadAllBytes(Path.Combine(FromPath));

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Hostname);
                request.Credentials = new NetworkCredential(Username, Password);
                request.EnableSsl = true;
                request.ContentLength = b.Length;
                request.Method = WebRequestMethods.Ftp.UploadFile;
                if (b != null)
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(b, 0, b.Length);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }

        }
    }

}

0 个答案:

没有答案