Can't upload to IIS Ftp website with different host using FtpWebRequest: 530 Valid hostname is expected

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

  •  25-09-2022
  •  | 
  •  

I have a command line app that uploads to FTP. I've used it without problems, but know I have 2 FTP sites that have different hostnames and I seems that the FtpWebRequest don't send something to the server.

Using a ftp client (Beyond Compare) I have no problem.

enter image description here

The code that uploads:

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(Usuario, Clave);
            request.UsePassive = Pasivo;

            // Copy the contents of the file to the request stream.
            byte[] fileContents = System.IO.File.ReadAllBytes(file); 
            request.ContentLength = fileContents.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

It's there a way to send the HOST command?

More data:

  • The .net exception is "The remote server returned an error: (530) Not logged in”
  • There's no error if I use the IP address of the server and add a binding with an empty hostname
有帮助吗?

解决方案

Solved adding the host to the username as described here

 request.Credentials = new NetworkCredential(Host + "|" + Usuario, Clave);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top