0

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
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206

1 Answers1

0

Solved adding the host to the username as described here

 request.Credentials = new NetworkCredential(Host + "|" + Usuario, Clave);
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206