简体   繁体   中英

Exception on uploading big file by FTP

I'm making a FTP client and trying to upload file to server (~300 MB), but I get following error when nearly 100 MB of the file were transfered:

The underlying connection was closed: An unexpected error occurred on a receive.

Here's my code:

private void UploadFile(string filepath, string filename)
    {
        try
        {
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://" + server + "/" + filename);

            //ftp.KeepAlive = false;
            //ftp.Timeout = 1000000;
            //ftp.UsePassive = true;
            //ftp.ReadWriteTimeout = 100000;

            Path.GetFileName(filepath);
            ftp.Credentials = new NetworkCredential(username, password);
            ftp.Method = WebRequestMethods.Ftp.UploadFile;


            FileStream stream = File.OpenRead(filepath);
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            stream.Close();


            Stream requestStream = ftp.GetRequestStream();
            //requestStream.ReadTimeout = 1000000;
            //requestStream.WriteTimeout = 1000000;
            requestStream.Write(buffer, 0, buffer.Length);
            requestStream.Close();         

            FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
            response.Close();
        }
        catch (Exception ex) { CreateRunLogFile(ex.Message); }

        CreateRunLogFile("Uploading of file " + filepath + " ended.");
    }

I try to use,

ftp.KeepAlive = false;
ftp.Timeout = 1000000;
ftp.UsePassive = true;

But it didn't help.

Check the destination firewall settings. If it is a LINUX server running vsFTPd then the server ftp service has FILESIZE and TIMEOUT settings in the config file.

Be sure to restart vsFTPd service after FILESIZE and TIMEOUT settings are adjusted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM