''' <summary>
''' Down load file from FTP site With progress & Write the Downloaded Memory Steram To File Stream
'''
''' <Status>BUG</Status>
'''
''' <issues>
''' Unable to track Byte Write From Memory Stream To File stream
''' Since Method BytesRed = DownLoadedMomoryStream.Read(WritingByteArray, 0, 1048576)
''' Reads all bytes to BytesRed at once, but not in a Progressive Sequeence
''' Therefore Unable to Display the profress Bar Progress
''' </issues>>
'''
''' </summary>
Private Sub DownLoadFile()
'Down load destination On local file system
Dim downloaddestination As String = $"{My.Settings.DownLoadPath}/{_DestinationFileName}"
downloaddestination = downloaddestination.Replace("/", "")
'Initialize FtpManager a Local class, Which can able to return the own loaded memory stream
Dim _FileToDownLoadFromServer As String = "/Img/222.jpg"
Dim f As New FtpManager(_ACCID, "remoteclient", "26101982", downloadingfilepath:=_FileToDownLoadFromServer)
' Get the Memory Stream Of Server File From f Class
Dim DownLoadedMomoryStream As MemoryStream = f.DownLoadFileStream
Dim WritingByteArray(1048576) As Byte
Dim DownLoadedStreamLength As Long = DownLoadedMomoryStream.Length - 1
Dim BytesRed As Integer = 0
'the OutPut File Stream to write
Dim WritingFileStream As New FileStream(downloaddestination, FileMode.OpenOrCreate, FileAccess.ReadWrite)
Using WritingFileStream
If Not DownLoadedMomoryStream Is Nothing Then
' Reset the DownLoadedMomoryStream Position to 0,
' Since Initialized @ Dim DownLoadedStreamLength As Long = DownLoadedMomoryStream.Length - 1
DownLoadedMomoryStream.Position = 0
'TODO:
' DownLoadedMomoryStream.Position Becoming Equal to its size
' After the BytesRed = DownLoadedMomoryStream.Read(WritingByteArray, 0, 1048576)
' & Hence the While loop Terminates
' & Bgw_Download.ReportProgress Remains @ 1 %
While DownLoadedMomoryStream.Position < DownLoadedStreamLength
BytesRed = DownLoadedMomoryStream.Read(WritingByteArray, 0, 1048576)
WritingFileStream.Write(WritingByteArray, 0, BytesRed)
' Report the progress to back ground worker named Bgw_Download
Bgw_Download.ReportProgress(Math.Round(DownLoadedMomoryStream.Position / DownLoadedStreamLength, 0))
End While
End If
WritingFileStream.Close()
WritingFileStream.Dispose()
End Using
End Sub