c# – 如何使用自动恢复工具下载ftp文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何使用自动恢复工具下载ftp文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2723字,纯文字阅读大概需要4分钟。
内容图文
![c# – 如何使用自动恢复工具下载ftp文件](/upload/InfoBanner/zyjiaocheng/814/4c5bdec2d1234f28bb50487de0d899b6.jpg)
我有一个问题,问题是我可以下载ftp文件但我下载的文件没有恢复设施和多部分文件下载,因为有超过500 MB文件的大文件我不能连续下载文件因为我断开连接并且它从头开始下载我希望我的代码是一个恢复工具,如果它断开连接
我正在使用的代码是
public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
//MessageBox.Show(reader.ReadToEnd());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
//MessageBox.Show(response.StatusDescription);
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}
private void Download(string filePath, string fileName)
{
FtpWebRequest reqFTP;
try
{
//filePath = <<The full path where the file is to be created.>>,
//fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnDownload_Click(object sender,EventArgs e)
{
FolderBrowserDialog fldDlg = new FolderBrowserDialog();
if (txtUpload.Text.Trim().Length > 0)
{
if (fldDlg.ShowDialog() == DialogResult.OK)
{
Download(fldDlg.SelectedPath, txtUpload.Text.Trim());
}
}
else
{
MessageBox.Show("Please enter the File name to download");
}
}
我想在我的代码中使用简历设施,
如果有人能帮助我,我会非常感激,
提前致谢
解决方法:
在开始下载之前,请检查本地文件系统上是否存在该文件.如果存在,则获取大小并将其用于FtpWebRequest对象的ContentOffset成员.但是,FTP服务器可能不支持此功能.
内容总结
以上是互联网集市为您收集整理的c# – 如何使用自动恢复工具下载ftp文件全部内容,希望文章能够帮你解决c# – 如何使用自动恢复工具下载ftp文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。