Protocol breach problems on FTP Server (Ftpwebrequest)

Asked

Viewed 77 times

1

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

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

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

"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 make the mistake 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 app runs in the same place as the backup. I’ve looked everywhere and I can’t find an answer.

  • Hello Peter. You could edit the question with the stack trace complete? Another thing, from your remote server you can access ftp with the application user and password and perform these operations (e. g., mkdir)?

  • Hi Anthony, I got it here, obg :D

1 answer

0


Guys 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 inside the FTP server.

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

Thank you for your attention :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.