The requested URI is not valid for this FTP command

0

I'm having problems trying to upload a file via FTP, I get the error

  

The requested URI is not valid for this FTP command.

Code:

FtpWebRequest resquest = (FtpWebRequest)WebRequest.Create(new Uri(NombreServidor));
resquest.Method = WebRequestMethods.Ftp.UploadFile;
resquest.Proxy = null;
resquest.UseBinary = true;
resquest.Credentials = new NetworkCredential(Usuario, Clave);

StreamReader ftpStream = new StreamReader(NombreCompletoArchivo);
FileStream fs = File.OpenRead(NombreCompletoArchivo);
byte[] Contenido = Encoding.UTF8.GetBytes(ftpStream.ReadToEnd());
ftpStream.Close();
resquest.ContentLength = Contenido.Length;

Stream requestStream = resquest.GetRequestStream();
requestStream.Write(Contenido, 0, Contenido.Length);
requestStream.Close();

FtpWebResponse respuesta = (FtpWebResponse)resquest.GetResponse();

I hope you can help me.

    
asked by Ramón Zoquier 22.04.2017 в 00:13
source

1 answer

1

This error is sent to you because in the .Create(new Uri(NombreServidor)) method you must specify and / or concatenate the file name so it looks like this:

FtpWebRequest resquest = (FtpWebRequest)WebRequest.Create(new Uri(NombreServidor + "/" + NombreArchivo));

Where in the variable NombreArchivo goes the full path as well as the name of the file.

Source : official documentation of the FtpWebRequest ( in English ), section operations to upload to file to an FTP server.

Update

Due to the error that now shows you:

  

Error in the Remote server: (530) You have not logged in.

The official documentation (in English) of the error says it can be presented for 4 reasons:

  • The Allow only anonymous connections security setting has been disabled in the Microsoft Management Console (MMC).
  • The user does not have permission log in locally in the user manager.
  • The user does not have permission to access the computer from the network .
  • The name of the domain has not been specified in conjunction with the user's name (it must have the form DOMAIN \ username )

Recommendation: review these 4 points, take a look at the official documentation as there is more complete information and as you will see, everything is related to the user and password, now the problem has been isolated and you already know what to correct.

    
answered by 22.04.2017 в 01:08