Can enter FTP using Filezilla but .NET gives “The requested URI is invalid for this FTP command.” [duplicate]

StackOverflow https://stackoverflow.com//questions/25014131

  •  21-12-2019
  •  | 
  •  

Vra

I am trying to upload a file, to an external FTP server. I can access the server using FileZilla, but not in my C# program.

In my documentation, I retrieved an URL which was:

ftp.richrelevance.com

I try to access that URL in my .NET program, but get a:

System.Net.WebException: The requested URI is invalid for this FTP command.

I tried this path as well:

ftp://ftp.richrelevance.com

But get the same error.

Any idea what path the program expects?

Filezilla settings that works:

enter image description here

Ftp code

  using(var fs = File.OpenRead(zipFileName)) 
            {
                var ms = new MemoryStream();
                ms.SetLength(fs.Length);
                fs.Read(ms.GetBuffer(), 0, (int) fs.Length);

                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpUrl);
                ftp.Credentials = new NetworkCredential(ftpUid, ftpPassword);

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;


                byte[] buffer = new byte[ms.Length];
                ms.Read(buffer, 0, buffer.Length);
                ms.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
Was dit nuttig?

Oplossing

have you tryed includig the ftpfile name when creating request?

 FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpUrl+ "/" + Path.GetFileName(zipFileName));
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top