3 Replies - 289 Views - Last Post: 06 February 2013 - 06:56 AM Rate Topic: -----

#1 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

FTP Uploading crash issue

Posted 04 February 2013 - 03:44 AM

Basically the program uploads multiple files selected by the user one by one onto an ftp server while uploading an html file named after those individual filesonto the same server.
Dim dr As DialogResult = Me.OpenFileDialog1.ShowDialog()

      If (dr = System.Windows.Forms.DialogResult.OK) Then
        
          'Selecting multiple files here
          Dim N As Integer = 0
          For Each myFileName In OpenFileDialog1.FileNames
              Try

                  Dim MyAdvancedWebClient As New MyAdvancedWebClient
                  MyAdvancedWebClient.FileName = OpenFileDialog1.SafeFileNames(N)
                  Dim myUri As New Uri("ftp://testing.com/" & OpenFileDialog1.SafeFileNames(N))
                  MyAdvancedWebClient.Credentials = New System.Net.NetworkCredential("username", "password")


                  'Uploading of main file
                  MyAdvancedWebClient.UploadFileAsync(myUri, OpenFileDialog1.FileNames(N))


                  'Uploading the HTML file here

                  Dim b As New UriBuilder()
                  b.Host = "testing.com"
                  b.UserName = "username"
                  b.Password = "password"
                  b.Port = 21
                  b.Path = "/" & OpenFileDialog1.SafeFileNames(N) & ".html"
                  b.Scheme = Uri.UriSchemeFtp
                  Dim g As Uri = b.Uri

                  Dim c As System.Net.FtpWebRequest = DirectCast(System.Net.FtpWebRequest.Create(g), System.Net.FtpWebRequest)
                  c.Method = System.Net.WebRequestMethods.Ftp.AppendFile
                  Dim h As System.IO.Stream = (c.GetRequestStream)
                  Dim SW As New System.IO.StreamWriter(h)
                  Dim contents = "<html><head></head><body></body></html>"
                  SW.WriteLine(contents)

                  SW.Close()
                  h.Close()


              Catch SecEx As SecurityException
                  ' The user lacks appropriate permissions to read files, discover paths, etc.
                  MessageBox.Show("Security error. Please contact your administrator for details.\n\n" & _
                      "Error message: " & SecEx.Message & "\n\n" & _
                      "Details (send to Support):\n\n" & SecEx.StackTrace)
              Catch ex As Exception
                  ' Could not load the File - probably permissions-related.
                  MessageBox.Show(("Cannot Select File: " & myFileName.Substring(myFileName.LastIndexOf("\"c)) & _
                  ". You may not have permission to read the file, or " + "it may be corrupt." _
                  & ControlChars.Lf & ControlChars.Lf & "Reported error: " & ex.Message))

              End Try
              N = N + 1
          Next myFileName
  
      End If


Everything works fine, but if the user selects more than 2 files the program stops responding.
What do you think the problem here is?
(no error recorded during debug, the program just stops responding.)

Is This A Good Question/Topic? 0
  • +

Replies To: FTP Uploading crash issue

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: FTP Uploading crash issue

Posted 04 February 2013 - 07:04 AM

Since you're uploading in the same thread as the GUI, I'm going to assume that "stops responding" just means the application is so busy it doesn't have time to paint the form or deal with windows messages like mouse clicks.


[*]Q:Make a progress bar work on its own thread to show progress to the user while work is being done?
A: Background worker tutorial




[*]Q:...do multi-threading? Having a problem with cross-threading...


[*]Q: ...Why my multi-thread throws a cross-threading error when it tries to update my GUI?
A: Your thread shouldn't be trying to affect any GUI at all: Ever.
Spoiler

Was This Post Helpful? 0
  • +
  • -

#3 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: FTP Uploading crash issue

Posted 05 February 2013 - 08:22 AM

View PosttlhIn`toq, on 04 February 2013 - 07:04 AM, said:

Since you're uploading in the same thread as the GUI, I'm going to assume that "stops responding" just means the application is so busy it doesn't have time to paint the form or deal with windows messages like mouse clicks.


[*]Q:Make a progress bar work on its own thread to show progress to the user while work is being done?
A: Background worker tutorial

So basically i have to run
  'Uploading the HTML file here

                Dim b As New UriBuilder()
                b.Host = "testing.com"
                b.UserName = ""
                b.Password = ""
                b.Port = 21
                b.Path = "/public_html/hello123/" & OpenFileDialog1.SafeFileNames(N) & ".html"
                b.Scheme = Uri.UriSchemeFtp
                Dim g As Uri = b.Uri

                Dim c As System.Net.FtpWebRequest = DirectCast(System.Net.FtpWebRequest.Create(g), System.Net.FtpWebRequest)
                c.Method = System.Net.WebRequestMethods.Ftp.AppendFile
                Dim h As System.IO.Stream = (c.GetRequestStream)
                Dim SW As New System.IO.StreamWriter(h)
                Dim contents = "<html><head></head><body></body></html>"
                SW.WriteLine(contents)

                SW.Close()
                h.Close()


within a background worker? creating a new thread?
Was This Post Helpful? 0
  • +
  • -

#4 Bluezap  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 305
  • Joined: 19-January 12

Re: FTP Uploading crash issue

Posted 06 February 2013 - 06:56 AM

And connecting the openfiledialog data onto the code in the background worker will be tricky wont it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1