Problems with protocol violation on FTP Server (FTPWebrequest)

1

In the company I work for, I have two servers: one that belongs to us and one third-party provider. I have to make a copy of the system files that is in the third-party provider for our local server. Basically a backup .

I'm using the FTPWebRequest class to do list, download, and create directory if they do not exist.

While I was running the application on my PC, I was able to download it normally. When I send the application to our local server and put it to execute it happens the following error:

"The underlying connection was closed: The server committed a protocol violation."

in the following method:

WebUI.FTPClient.MakeDirFTP(String diretorio)

The method he claims to give the error is this:

 public void MakeDirFTP(string diretorio) {
     try {
         FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://diretorio/subDiretorio/Backup/" + diretorio);
         request.Method = WebRequestMethods.Ftp.MakeDirectory;
         request.Proxy = null;
         request.UseBinary = true;
         request.UsePassive = true;
         request.Timeout = 6000000;
         request.KeepAlive = true;
         request.Credentials = new NetworkCredential(usuario, senha);
         FtpWebResponse response = (FtpWebResponse)request.GetResponse();
         Stream responseStream = response.GetResponseStream();
         responseStream = response.GetResponseStream();
         responseStream.Close();
         response.Close();
     } catch (Exception ex) {
         throw ex;
     }

}

This application runs in the same place as the backup . I've looked everywhere and I did not find an answer.

    
asked by anonymous 20.09.2016 / 15:47

1 answer

0

I found out what the error was: P

The application was already inside the server so there was no reason to try to authenticate the login, since the application already had access to the directories.

I did this to create the directories within the FTP server.

if (ConfiguracaoLocalOuServidor.EstouNoServidor())
            {
                string caminho = HttpContext.Current.Server.MapPath("").Replace("\Admin", "") + "\Backup\" + diretorio + "\";                                      
                Directory.CreateDirectory(caminho);
            }

Thanks for the attention: D

    
21.09.2016 / 16:08