Question How to upload files and subfolders or in zip,rar using my code ?

Polas5

Member
Joined
Jul 23, 2011
Messages
14
Location
Alytus, Lithuania
Programming Experience
Beginner
Hello.
Here I have a small problem with ftp upload all files and subfolders.
Here is my code.

VB.NET:
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         OpenFileDialog1.ShowDialog ()
         TextBox1.Text = OpenFileDialog1.FileName
         Label3.Text = OpenFileDialog1.SafeFileName
     end Sub

     Private Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
         My.Settings.host = TextBox2.Text
         My.Settings.username = TextBox3.Text
         My.Settings.password = TextBox4.Text
         My.Settings.Save ()
         My.Settings.Reload ()

         try
             My.Computer.Network.UploadFile (TextBox1.Text, "ftp://ftp. TextBox2.Text & &" / "+ Label3.Text, TextBox3.Text, TextBox4.Text, True, 500)
         Catch ex As Exception
             MsgBox (ex.Message)

         end Try
     end Sub
     Private Sub Form1_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         TextBox2.Text = My.Settings.host
         TextBox3.Text = My.Settings.username
         TextBox4.Text = My.Settings.password
     end Sub

The program is well-checked everything but how do I upload all files and subfolders?
 
You don't. UploadFile does what it says: it uploads a file. If you want to upload a compressed file then you have to create the compressed file first, which you can't do with just the .NET Framework alone. It supports GZIP compression only, which supports only one file per archive. You can use a third-party component, such as SharpZipLib or DotNetZip, to create an archive in ZIP or some other format. You can then upload that one file as you are now.

If you want to be able to upload multiple files and folders separately, i.e. without creating the archive first, then you will have to use an FtpWebRequest, at least for creating the folders. You would use a recursive method to traverse your folder tree and loop through the files each one contains. There are lots of examples around of recursive file searching.
 
I tried more than once and so as you write is not in any way.
Everything has been tested

And there are no webreaquest examples as normal even started and what it all started how to begin from.

I'm thinking maybe you could help me?

I know google is full examples but is not what I need.
And by the way may not always get answers from it.
No one knows how to do it.
Strange is not it? But it's true.

I really do not know how I start with webreaquest.
Just me do not need a program, which I am trying to create with this beginner's way and really did not think that a good way to start from this or not?
You see, the problem is that trying to connect to your server administration, they responded to no good.
It is still unresolved why they have not accepted the filezilla my files but just take me out from server.
And do appear here not their fault and fault filezilla program.
So while I can not put the server downloaded any files.
Using some of this newcomer and lifestyle program, which it is spent well and the file, choose to upload creative imagery as into server.
That's why I scream your help.
 
Last edited:
Ok this is good code but how to make it with textbox not with simple like c:\blabla.zip.
I want browse from my hard drive and put the path into textbox and then upload to ftp or from it ?

Thanks.
 
It will be better if someone knows how to upload folders or subfolders.
Given that that is not possible, you should probably forget that idea. You can create a single directory or upload a single file at a time. If you want to effectively upload a folder and all the files and subfolders it contains then you must perform one operation for each folder and one for each file. You would traverse the local file system using a recursive method. You'll find lots of examples of recursive file searches on the web, generally using the GetFiles and GetDirectories methods of the Directory or DirectoryInfo classes. As you visit each folder and file, you can do whatever you like with them.
 
Ok this is good code but how to make it with textbox not with simple like c:\blabla.zip.
I want browse from my hard drive and put the path into textbox and then upload to ftp or from it ?

Thanks.
A String is a String, whether you hard-code it or it comes from the Text property of a TextBox or the FileName property of an OpenFileDialog. Once you have a String containing a file path, however you get it, you use it in exactly the same way.
 
Back
Top