互联网中断后如何继续或恢复FTP上传 [英] how to continue or resume FTP upload after interruption of internet

查看:236
本文介绍了互联网中断后如何继续或恢复FTP上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

 FtpWebRequest请求=(FtpWebRequest) WebRequest.Create( ftp://someweb.mn/altanzulpharm/file12.zip); 
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = true;
request.UseBinary = true;
request.Credentials = new NetworkCredential(username,password);

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

Stream ftpstream = request.GetRequestStream();
ftpstream.Write(buffer,0,buffer.Length);
ftpstream.Close();

但互联网中断时,上传会中断。中断发生的时间非常短,几乎是一毫秒。但上传永远不会中断!



是否可以在互联网中断后继续上传?

解决方案

我不相信FtpWebRequest在失去连接后支持重新连接。如果服务器支持,您可以从给定位置恢复上传(这种支持不是必需的,可能不太常见,即重试下载)。

您需要设置 FtpWebRequet.ContentOffset 上传。从文章的一部分样本:

pre $ FtpWebRequest请求=(FtpWebRequest)WebRequest.Create(serverUri);
request.ContentOffset = offset;






FTP协议本身的恢复内部细节 - RFC959:3.5 - 错误恢复和重新启动。显示重试代码下载的问题 - 使用c#从FTP下载,可以当失败时重试


I am using below code (c# .net3.5) to upload a file:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://someweb.mn/altanzulpharm/file12.zip");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = true;
request.UseBinary = true;
request.Credentials = new NetworkCredential(username, password);

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

Stream ftpstream = request.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();

but the upload breaks when internet interrupted. Interruption occurs for a very small amount of time, almost a millisecond. But uploading breaks forever!

Is it possible to continue or resume uploading after interruption of internet?

解决方案

I don't believe FtpWebRequest supports re-connection after losing connection. You can resume upload from given position if server supports it (this support is not required and presumably less common that retry for download).

You'll need to set FtpWebRequet.ContentOffset upload. Part of sample from the article:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.ContentOffset = offset;


Internal details of restore in FTP protocol itself - RFC959: 3.5 - Error recovery and restart. Question showing retry code for download - Downloading from FTP with c#, can't retry when fail

这篇关于互联网中断后如何继续或恢复FTP上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆