1


I want to upload a file to a server via ftp, but I can't get the file-bytes, because byte[] fileContents = File.ReadAllBytes(file); only supports files with an amount of 2GB.

How can I solve the problem?

Is there any alternative to File.ReadAllBytes(file) ?

I don't want to use a StreamReader, because of Zip file is getting corrupted after uploaded to server using C#

Community
  • 1
  • 1
Ismoh
  • 1,074
  • 2
  • 12
  • 35
  • If you're just uploading a file, why are you reading its contents? Maybe you can get away with just File.Move. – Andrew Dec 19 '14 at 20:39
  • 2
    Read and post the file block by block (for ex using 64K blocks). Do you think loading a huge file to memory is a good thing? – L.B Dec 19 '14 at 20:44
  • It's the first time I work with ftp coding, and I found some examples, which first load the file. How can I post the file block by block ? – Ismoh Dec 19 '14 at 20:48
  • @Ismoh It is not related with *ftp-coding*. Suppose you want to copy a file. Would you read all file at once and write it to another location? What if the file is much much bigger than your memory? – L.B Dec 19 '14 at 21:21
  • Oh yes. You'r right, but I don't know how to read a file in blocks. Let me look up this at google. – Ismoh Dec 19 '14 at 21:27
  • 1
    See the methods `stream.Read` `stream.Write` and for your special case `stream.CopyTo` – L.B Dec 19 '14 at 22:05
  • Thanks. Maybe you can put the comment in an answer, so that I can accept it as 'problem solved', because I found this: http://stackoverflow.com/questions/230128/how-do-i-copy-the-contents-of-one-stream-to-another – Ismoh Dec 19 '14 at 22:51

0 Answers0