Skip to main content

 none
Windows Form Application - FTP in Win Explorer.exe RRS feed

  • Question

  • hi, im new to coding, ive got my basic application made up, now im just trying to finalize some of the features i want. one of the things im struggling with is that i want to have a text box that i can type an ip address (for FTP) or a file location in (ex. "C:\users\public\documents") inside of a windows explorer .EXE window. So far, ive got it setup to connect to my FTP just by setting this command up on a button:

    • System.Diagnostics.Process.Start("explorer.exe", @"ftp://192.168.0.xx");

    however this doesnt fully achieve what im wanting, this just helps me with FTP for now, but my FTP address changes every so often so having to recode the software to change the ip everytime would kinda get annoying, so i just want to setup a textbox that is monitored by the button so that it will open the Explorer.exe up to whatever is typed in the Textbox, and if there is nothing, to prompt me with a messagebox that reads "Invalid Destination!"

    so last example, i want to be able to type my ftp servers ip address into a textbox, click the button and have my FTP server opened up inside of Explorer.EXE, aswell as being able to type a physical File Location into the textbox, Such as C:\users\public\documents and have it open up Explorer.EXE to my Documents Folder. Any Help would be GREATLY APPRECIATED!

    Saturday, September 14, 2019 11:22 AM

All replies

  • Hello,

    Not what you are looking for but would recommend not doing this in code but instead using a free tool such as FileZilla as writing this in code is more complex that I believe you think it is. And if doing something in code something like this (also not what you asked for) this code would be a better choice.

    Why provide you with things out not what you are looking for? Because there are sometimes better alternatives which may or may not be acceptable but if you don't know about them and they might be acceptable, well you can figure this out :-)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, September 14, 2019 1:33 PM
    Moderator
  • I don't think Explorer is viable, and you should look into FTP solutions like Filezilla.
    Saturday, September 14, 2019 1:46 PM
  • Hi brys U,

    Thank you for posting here.

    If you want to connect to your ftp, I don't suggest that you use process.start method. As usual, we need to write it in a common method.

    I have written the similar code in the following link, you could have a look.

    download each file in folder

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 5:53 AM
    Moderator
  • In almost every corporate environment, your machine will be registered by name with a DNS server.  You should just use the local name instead of hardcoding a dynamic IP address.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, September 16, 2019 4:43 PM
  • So you want to be able to type either an IP address or file path into a textbox and it automatically open in Windows Explorer? That's pretty straightforward and in fact your example call to Process.Start should work but you need to make a couple of adjustments. Firstly you need to retrieve the value from the Textbox rather than hard coding it.

    private void button1_Clicked ( object sender, EventArgs e )
    {
       var targetPath = textBox1.Text;
    
       Process.Start("explorer.exe", targetPath);
    }

    The harder part is getting Explorer to show what you want. If you pass an IP address to Explorer then it'll assume a web address. If you want it to use FTP then you need to add the scheme. But you might be able to tell the difference between an IP address and a file location but the computer can't so you'll have to figure out which one you have. One approach might be to simply try to parse the IP address. If that succeeds then assume FTP otherwise assume a file path.

    //Not tested
    private string GetExplorerPath ( string value )
    {
       //Check for IP address
       if (IPAddress.TryParse(value, out var ip))
          return $"ftp://{ip}";
    
       return value;
    }
    
    //Then use it
    private void button1_Clicked ( object sender, EventArgs e )
    {
       //Not doing any error checking such as empty string here...
       var value = GetExplorerPath(textbox1.Text);
    
       Process.Start("Explorer.exe", value);
    }


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 17, 2019 2:35 PM
    Moderator