Was wondering if you could point me at a right direction on how to achieve this...
I'm currently working on an application that will check the filespace consumed in a remote FTP server that has folders, subfolders and files.
I managed to get some information using System.NET via FtpWebRequest, FtpResponse, WebRequestMethods & System.IO in my code. However, I'm stuck in how I could manage to traverse subdirectories using the said classes.
Was wondering if you could point me at the right direction on how I could achieve this using C#? Or if there are alternatives that I could use (i.e. powershell, windows command line, etc)? I've tried looking at Chillkat ftp2, but it is not free and some FTP client components have no documentation nor examples on how to use it.
Thank you.
You do this the same way you would download a file. Put the directory in the URL, then set the FtpWebRequest.Method property to WebRequestMethods.Ftp.ListDirectory. This will give you the list of files/subfolders, which you can then traverse manually.
Here's a blog post showing the process, as well as using ListDirectoryDetails to differentiate between files and subdirectories.
Related
Using this namespace:
Microsoft.VisualBasic.FileIO;
I am copying a source folder from on our network to the user's computer using this line of code:
FileSystem.CopyDirectory(networkDir.FullName, localDir.FullName, UIOption.AllDialogs, UICancelOption.DoNothing);
This opens up that nice copy window we are all familiar with, which shows:
that my application is not hung up and is thinking.
how long the transfer will take.
Problem is that this window also shows the source and destination locations of the copy. I don't really want the user to see the IP and exact file path where the files are coming from.
I would like to avoid creating a big recursive foreach loop to make a directory copier, on top of having to provide an active UI that shows that the program is thinking. Are there any good workarounds or other solutions to achieve a directory copy without the source location being made public?
source location being made public
Do you control the source being downloaded from? If it's from a webserver you could make the whole thing ephemeral, and even use a hosts file entry to obfuscate the IP:
"Downloading from http://daves.server.honest/downloads/onetime/23i23i34248723084r/dir.zip"
Could be essentially useless to the 2nd person who tries to use the path.
Sadly if you're on a network drive rather than a webserver, your options are slightly more limited since it all has to be 'real' :/
I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.
I am currently building an application that will need to use all of the Control Panel's shortcuts which can be found in "shell:::{ED7BA470-8E54-465E-825C-99712043E01C}" aka GodMode folder.
However, when I try to access the folder through code, I get no result. This also happens when I try to enumerate the files using the command prompt (using 'dir').
Any help is appreciated.
Thanks
The God Mode is implemented in the Windows Explorer Shell. If you look at it at the file system level it's just an ordinary folder with a peculiar name. That's why you won't see anything special in it when reading it as a directory in code. If you look at it with the command prompt it's the same - just a plain empty folder with a peculiar name.
You won't be able to access the shortcuts through the file system API, so you have to look for an API that exposes the control panel contents instead.
I would like to be able to search for a folder by name within a user's files in C#. The reason for this is to enable a process which utilizes two applications that are otherwise not communicating with one another. (The process is essentially a file hand off, and the applications cannot communicate as one is a proprietary app). If this is possible, any ideas or best practices would be much appreciated.
Thanks,
badPanda
Start at root (or the root where this directory might be found) with System.IO.DirectoryInfo. Call GetDirectories to get all of the directories within this directory. Call GetDirectories recursively and compare to your desired name until you find it.
In my project I need to watch multiple FTP Folders continuosly, if any new file comes i need pick the filename and do some process. If that is normal Windows/Local File System folder I can achieve this by using SystemFileWatcher of .net. Is there any thing like SystemFilewatcher to watch FTP folders?
nrk
No this doesn't exist, because a FTP folder can't send you any events about any change. So you have to write your own little class with a background worker. This one asks the ftp server for directory listing periodically and compares it against the last list obtained. Then you can fire some events depending on the happen changes.
So you'll get an event class in .Net but under the hood it will be pull model with lot of traffic on the wire.
I don't understand #Oliver's answer. Of course there is a way to use the FileSystemWatcher class to watch events in an FTP folder, and it's not a pull model. I'm working on creating something just like it right now, using the model as described in this MSDN article:
Windows Services: New Base Classes in .NET Make Writing a Windows Service Easy
To effectively use the FSW, you build it into a Windows Service, and have it watch the FTP folder(s). Of course, you'd need to install it on the FTP server (not somewhere else in the network), but it would do exactly what you need.