Ftpwebrequest - Error large files

Asked

Viewed 241 times

1

I have a c# desktop application running a few months on a client. The same requested a module to perform uploads and downloads on an FTP server, the database is currently in the clouds by Kinghost, as this company already offers the service, I chose to continue in it, but I’m having some problems...

My algorithm does not present any problem to upload small files, however more than 20MB files is occurring the following error: "The underlying connection was closed: Unexpected error on a receipt"

I contacted the hosting company and was informed that no problem was located.

DETAIL: after few minutes of error, while checking the ftp the file is there...

Follows algorithm:

                    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(cboServidor.Text + cboGrupoArquivo.Text + "/" + Path.GetFileName(openFileDialog1.FileName));
                    request.Method = WebRequestMethods.Ftp.UploadFile;
                    request.Credentials = new NetworkCredential(txtUsuario.Text, txtSenha.Text);
                    request.UsePassive = true;
                    request.UseBinary = true;
                    request.KeepAlive = false;


                    FileStream stream = File.OpenRead(openFileDialog1.FileName);
                    byte[] buffer = new byte[stream.Length];

                    stream.Read(buffer, 0, buffer.Length);
                    stream.Close();

                    Stream reqStream = request.GetRequestStream();
                    reqStream.Write(buffer, 0, buffer.Length);
                    reqStream.Close();
  • 1

    Test on another FTP to see if the problem persists. In the worst case, try to send the file in pieces, doing APPEND instead of sending it at once (not ideal, but if you have to continue in the same hosting, and can not solve the timeout or error). Anyway, the ideal is to locate the problem. Try with buffers of different sizes to see if it changes the behavior. Start one of some 4k, then increase. Also try to alternate the request.KeepAlive, It may be that the FTP of such hosting needs these contours.

  • I put time to timeout and changed Keepalive to true...?

  • Keep Alive is exchanging packages from time to time to not knock down the connection, it may be one of the causes. But you can’t say without tests

No answers

Browser other questions tagged

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