English 中文(简体)
FtpWebRequests 不要再下载8820多份数据
原标题:FtpWebRequest not downloading more then 8820 bytes of data
  • 时间:2011-10-17 06:38:35
  •  标签:
  • c#
  • ftp

我试图通过FtpWebRequest将档案从A站点下载并上载到B站点。

我面临的问题是,在我下载Im的档案时,数据没有增加8820份。

这里我使用的是:

public FtpFile Download(string path)
{
  string fullpath = ConstructFullpath(path);

  FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fullpath);
  request.Method = WebRequestMethods.Ftp.DownloadFile;
  // login
  request.Credentials = new NetworkCredential(Username, Password);  

  FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  Stream responseStream = request.GetResponse().GetResponseStream();

  byte[] data = new byte[20000];
  int length = responseStream.Read(data, 0, data.Length);
  responseStream.Close();

  FtpFile file = new FtpFile(path, data, length);
  return file;
}

public bool Upload(FtpFile file)
{
  if (!DirectoryExists(GetDirectory(file.Path)))
  {
    CreateDirectory(GetDirectory(file.Path));
  }

  string fullpath = ConstructFullpath(file.Path);
  FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fullpath);
  request.Method = WebRequestMethods.Ftp.UploadFile;
  request.Credentials = new NetworkCredential(Username, Password);


  Stream stream = request.GetRequestStream();
  stream.Write(file.Data, 0, file.Length);
  stream.Close();

  FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  return true;
}

The First image shows the source directory. The second image shows the destination directory.

“源网络名录”</p

The destination web directory I have tried saving the files locally and have the same result.

最佳回答

页: 1

byte[] data = new byte[20000];
int length = responseStream.Read(data, 0, data.Length);
responseStream.Close();

不能保证所有数据都用单一电话阅读,你永远不能依靠这些数据。 您请在<代码>Read 返回时填写数据。

如果你重新使用“NET”4,Stream.CopyTo,就很容易做到:

MemoryStream ms = new MemoryStream();
responseStream.CopyTo(ms);

请注意,你还应使用<条码>,使用<>条码>,而不是明确关闭资源,包括<条码> FtpWebResponse。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签