vb.net - FTP Client uploads only 0KB files -


i having small problem ftp client.
choosing file works, renaming file 4 variables works.
it's upload causing me trouble. whenever file uploaded ftp server says 0kb.

i thinking of 2 possible problems:

visual studio tells me variable file used before has been assigned value, make sure isn't null did following.

dim file byte()    if (not file nothing)             strz.write(file, 0, file.length)             strz.close()             strz.dispose()             filesystem.rename(filename, originalfile)         end if 

this takes care of possible errors.

the second 1 fname, same warning file, , took care of same way.

another possibility code takes 4 variables , makes file , uploads it, hence 0kb size....

here's code:

dim filename string     dim originalfile string      private function enumeratecheckboxes(byval path string)         originalfile = path         dim fname string         each control in me.controls             if (typeof control combobox andalso directcast(control, combobox).selectedindex > -1)                 fname += cstr(control.selecteditem.key) + "_"             end if         next         try             fname = path + fname.substring(0, fname.length - 1) + ".jpg"         catch ex exception             msgbox(ex.message)             msgbox("stack trace: " & vbcrlf & ex.stacktrace)         end try         return fname     end function      public function opendialog()         dim fd openfiledialog = new openfiledialog()          fd.title = "selecteer een bestand"         fd.initialdirectory = "c:\"         fd.filter = "all files (*.*)|*.*|all files (*.*)|*.*"         fd.filterindex = 2         fd.restoredirectory = true          if fd.showdialog() = dialogresult.ok             dim filename string = fd.filename             filename = strreverse(filename)             filename = mid(filename, instr(filename, "\"), len(filename))             filename = strreverse(filename)             msgbox(enumeratecheckboxes(filename))         end if     end function      private sub button1_click(sender object, e eventargs) handles button1.click          dim request system.net.ftpwebrequest = directcast(system.net.webrequest.create("ip" & enumeratecheckboxes(filename)), system.net.ftpwebrequest)         request.credentials = new system.net.networkcredential("username", "password")         request.method = system.net.webrequestmethods.ftp.uploadfile          dim file() byte          try             filename = opendialog()             if (not filename nothing)                 system.io.file.readallbytes(filename)             end if         catch ex exception             messagebox.show(ex.message)             messagebox.show("stack trace: " & vbcrlf & ex.stacktrace)         end try         if (not filename nothing)             filesystem.rename(originalfile, filename)         end if         dim strz system.io.stream = request.getrequeststream()         if (not file nothing)             strz.write(file, 0, file.length)             strz.close()             strz.dispose()             filesystem.rename(filename, originalfile)         end if     end sub end class 

i have looked @ multiple threads same problem me.
threads this dont believe applies problem. if kind explain did wrong , how can fix , avoid in future, debugging still bit rough...

thank in advance!

visual studio giving warning because never assign file array. think on line have:

system.io.file.readallbytes(filename) 

you meant have:

file = system.io.file.readallbytes(filename) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -