download and extration-VBForums
Results 1 to 2 of 2

Thread: download and extration

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2013
    Posts
    12

    download and extration

    hey im trying to download a zip or rar file dosen't matter from a ftp, lets say my program is inside a folder and i want the files to automatis download to the same folder and then i should be extracted from zip to normal files i have all ready made a code but im very bad with the directions so can any help me

    Code:
    Imports System.Net
    Public Class MainForm
    
        Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Control.CheckForIllegalCrossThreadCalls = False
        End Sub
    
        Private Sub btnBrowseSave_Click(sender As Object, e As EventArgs) Handles btnBrowseSave.Click
            Dim newFolder As New FolderBrowserDialog
            If newFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtSavePath.Text = newFolder.SelectedPath
            End If
        End Sub
    
        Private Sub btnDownload_Click(sender As Object, e As EventArgs) Handles btnDownload.Click
            bWorker.RunWorkerAsync()
        End Sub
    
        Private Sub bWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bWorker.DoWork
            Dim buffer(1023) As Byte
            Dim bytesIn As Integer
            Dim totalBytesIn As Integer
            Dim output As IO.Stream
            Dim flLength As Integer
            Try
                Dim FTPRequest As FtpWebRequest = DirectCast(WebRequest.Create(txtFilePath.Text), FtpWebRequest)
                FTPRequest.Credentials = New NetworkCredential(txtFTPUsername.Text, txtFTPPassword.Text)
                FTPRequest.Method = Net.WebRequestMethods.Ftp.GetFileSize
                flLength = CInt(FTPRequest.GetResponse.ContentLength)
                lblFileSize.Text = flLength & " gb"
            Catch ex As Exception
    
            End Try
            Try
                Dim FTPRequest As FtpWebRequest = DirectCast(WebRequest.Create(txtFilePath.Text), FtpWebRequest)
                FTPRequest.Credentials = New NetworkCredential(txtFTPUsername.Text, txtFTPPassword.Text)
                FTPRequest.Method = WebRequestMethods.Ftp.DownloadFile
                Dim stream As System.IO.Stream = FTPRequest.GetResponse.GetResponseStream
                Dim OutputFilePath As String = txtSavePath.Text & "\" & IO.Path.GetFileName(txtFilePath.Text)
                output = System.IO.File.Create(OutputFilePath)
                bytesIn = 1
                Do Until bytesIn < 1
                    bytesIn = stream.Read(buffer, 0, 1024)
                    If bytesIn > 0 Then
                        output.Write(buffer, 0, bytesIn)
                        totalBytesIn += bytesIn
                        lblDownloadedBytes.Text = totalBytesIn.ToString & " gb"
                        If flLength > 0 Then
                            Dim perc As Integer = (totalBytesIn / flLength) * 100
                            bWorker.ReportProgress(perc)
                        End If
                    End If
                Loop
                output.Close()
                stream.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
           
    
        End Sub
    
        Private Sub bWorker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bWorker.ProgressChanged
            pBar.Value = e.ProgressPercentage
            lblPercent.Text = e.ProgressPercentage.ToString & "%"
        End Sub
    
        Private Sub bWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bWorker.RunWorkerCompleted
            MsgBox("Download Complete!")
    
            
    
        End Sub
    
    
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim sc As New Shell32.Shell()
            'Create directory in which you will unzip your files .
            IO.Directory.CreateDirectory(".")
            'Declare the folder where the files will be extracted
            Dim output As Shell32.Folder = sc.NameSpace(".")
            'Declare your input zip file as folder  .
            Dim input As Shell32.Folder = sc.NameSpace("./test.zip")
            'Extract the files from the zip file using the CopyHere command .
            output.CopyHere(input.Items, 4)
        End Sub
    End Class

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: download and extration

    So what's not working. Rather then us scan your code and work it out for our self why don't you spend time and effort making a detailed and descriptive post.

    Get rid of this Control.CheckForIllegalCrossThreadCalls = False and never use it again also.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.