c# - How to download .zip files through code? -
I have some zip files on an FTP server that I want to download via code but every time I Downloading and trying to open they are corrupt. Now with the stream. Although this method is fine for small files, you should not use it for very large files, because it will fill your memory very quickly and the byte size of files larger than 2 GB can not be stored as int 32 is. FtpClient conn = new FtpClient (); Conn.host = ftpFtpServerAddress; Conn.Credentials = New network credentials (ftpSrc u name, ftpSrcPwd); Var file = conn.getListing (ftpSrcFolder, FtpListOption.Modify | FtpListOption.Size); (File in fire file) {conn. Bin open read (file full name, new async callback (openerbackblack), new assisaggents () {client = conn, filename = file .name}); } Private Zero BeginOpenReadCallback (IAsyncResult AR) {AsyncArguments args = (AsyncArguments) ar.AsyncState; FtpClient conn = argsClient; Stream easth = conn.EndOpenRead (AR); (Using System.IO.FileStream fs = System.IO.File.Create (@ "C: \ temp \" + argsFileName)) {byte [bytes] = new byte [istream.Length + 10]; Int numBytesToRead = (int) istream.Length; Fs.Write (bytes, 0, pneumbytes, teoride); }}
Private Zero Start Opener Callback (IAsyncResult AR) {AsyncObject args = (AsyncObject) ar.AsyncState; FtpClient conn = args.conn; Stream easth = conn.EndOpenRead (AR); (Using System.IO.FileStream fs = System.IO.File.Create (@ "C: \ temp \" + args.filename)) {byte [] bytes = new byte [istream.Length]; Int bytesread = istream.Read (byte, 0, bytes lang); Fs.Write (Byte, 0, Bytesread); }}
Comments
Post a Comment