3 Replies - 9353 Views - Last Post: 13 January 2009 - 10:45 PM Rate Topic: -----

#1 crazyvonzipper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 09

FTP Recursive Treeview + FTP Speedup

Post icon  Posted 13 January 2009 - 12:36 AM

Hi, i am new to this forum, so if my questions aren't exactly the way they should be , please accept my apology...

The reason i moved forums is because i found that no one ever really helps you, but now i would like to ask for some proper help...

firstly, I am writing an application that makes backups on my server and locally...

I am using a 3rd party FTP library class that i find very useful in terms of flexibility etc..

no basically, what i did is this
1. Theres a treeview that loads the directories from the server :

#region Server Backup Directory Load
			if (radServerDatabase.Checked == true)
			{
				FTPDIRFORM.Show();
				treeView1.Nodes.Clear();
				this.Enabled = false;
				try
				{
					m_FTPLIB.server = txtftpServerName.Text;
					m_FTPLIB.user = txtftpUserName.Text;
					m_FTPLIB.pass = txtftpPassword.Text;

					foreach (string S in m_FTPLIB.ListDirectories())
					{
						/*		  Making parent node		  */
						TreeNode ParentNode = new TreeNode();
						ParentNode.Text = S.Substring(55);

						if (!S.Contains("."))
						{
							treeView1.Nodes.Add(ParentNode);
						}

						/*		  Making child node		   */

						m_FTPLIB.ChangeDir("//" + S.Substring(55) + "/");
						foreach (string S2 in m_FTPLIB.List())
						{
							m_FTPLIB.ChangeDir("//" + S.Substring(55) + "/");

							TreeNode ChildNode = new TreeNode();
							ChildNode.Text = S2.Substring(55);
							ParentNode.Nodes.Add(ChildNode);

							m_FTPLIB.ChangeDir(".");
						}

					}
					this.Enabled = true;
				}
				catch (Exception EX)
				{
					MessageBox.Show("Could not load ftp directories :\n" + EX.Message + "\n Try Updating the Ftp Settings ?");
					this.Enabled = true;
				}
			}
			#endregion	 



Now This works fine and loads a parent node as well as a child node into the treeview, but unfortunately this is not recursive... can anyone maybe tell me how to make this treeview load a list of recursive directories, files etc etc ?

Secondly, my FTP is lagging like a dying cow, is it possible to use threading in this particular situation ???
Or is there any other way of speeding up my loading process ???

Regards...

Is This A Good Question/Topic? 0
  • +

Replies To: FTP Recursive Treeview + FTP Speedup

#2 rtd2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-January 09

Re: FTP Recursive Treeview + FTP Speedup

Posted 13 January 2009 - 09:48 PM

FTP is essentially a request/response system... so in order to populate a treeview, your very best bet would be to begin with a collapsed tree. Load your parent level files and directories, and as you expand each tree node, call out to the FTP list command to load that node. Eliminate the need to run recursively. Recursively loading an entire treeview to represent an FTP site (and running recursively in generally) will never run optimally. If you populate a node each time you expand it or perform an action on it, it will be simpler to wrap your head around, and the directory contents of your node will be refreshed all the time - displaying any changes you may have performed on that node. Once you populate a node, make sure you have the information stored within the node itself to perform actions upon that item. You can do this by storing path information in a separate parameter of the node... (i.e. display only file and immediate folder names in the node's text, but store full path information in an alternate field, such as tooltiptext or tag). This isn't truly necessary, but it will make your tree more efficient by saving the time it would take to traverse your tree to find a full directory path to perform operations on particular files and folders.

If you really wanted to dynamically populate the entire treeview all at once... the only way I can see about doing so would be to perform a check on each node's child to determine whether that child node is a file or directory. If it is directory, you could then call a function to attach to the FTP with that path and populate that node's leaves. Depending on what your directory structure looks like though... this would take a LONG time. Imagining having to write this program for my own computer and not an FTP location immediately cuts out any reason for me (at least) to want all that information all at once - only to have to run it again the moment anything at all changes. Right about this time in my own exploration about 2 months ago, I decided to go with the method I mentioned in the paragraph above. It works like a charm!... and mine's web-based!! :)

I'm not sure how large of an FTP site you are dealing with, but if it contains a lot of files and folders, you'll want to do something similar to what I have just stated, if for nothing more than to make it run a whole lot faster.

This post has been edited by rtd2008: 13 January 2009 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

#3 rtd2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-January 09

Re: FTP Recursive Treeview + FTP Speedup

Posted 13 January 2009 - 10:24 PM

If you are going to try to syncronize your local directories with FTP directories, you can story root path information for each. You can easily use an instring comparison on your local working directory to sync up with the ftp. Once you know what your FTP location should be, you could run a function to populate that node and automatically either populate and display it or assign it as being the parent node altogether.

At this point, I would suggest checking out MSDN for everything you can find on FTPWebRequest. You might find that you are using a 3rd Party component that you really don't need. In the 3.5 Framework, you could extend built-in tools to do more than enough of what you want to accomplish.

I hope my posts have helped a little. If you want to discuss more, let me know.

~Reb
Was This Post Helpful? 0
  • +
  • -

#4 rtd2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-January 09

Re: FTP Recursive Treeview + FTP Speedup

Posted 13 January 2009 - 10:45 PM

Final thoughts about your post...

Threading your applications:

I've not yet created an application that runs on multiple threads that run different paths to accomplish the end-goal faster. I have created an application that runs the same functionality on multiple end-machines simultaneously on different threads though. If you're in that boat, then I could probably be of some help. Multithreading an application just to have it run on multiple threads between two machines is rather pointless though, in my opinion.

Your app could run with absolutely no over-thought process smoothly. I think you're delving too deep into the realm of terminology to solve a problem that could be solved in layman's terms.

If you need some code examples, I can probably come up with a few... but I will only code them in VB.NET.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1