1

I am trying to create a bootstrapper for a program and the error "System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect " Keeps popping up.

I have been stuck on this problem and have been guessing how to solve the problem.

String pname = "Fredysploit_v2";
String dlink = "https://pastebin.com/V5NcE09n";
string title = @"Title ";
Console.Title = pname + " Bootstrapper";

Console.ForegroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(title);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading new Files...");
WebClient wc = new WebClient();
string key = wc.DownloadString(dlink);
string path = @"Update\" + pname + ".exe";
System.Net.WebClient Dow = new WebClient();
string patch = (@"Update");
Directory.CreateDirectory(patch);
//My problem ↓
Dow.DownloadFile(key, path);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(pname + " Downloaded | Updated!");
Console.WriteLine($"Now open " + patch + " and Run " + pname + ".exe");
Console.ReadKey();

I expected the outcome to download the file off the text which is a link on pastebin but, the actual outcome was "System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect".

Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
Dread415
  • 31
  • 8
  • Have you debugged through the code? What's the value of `key`? – Jon Skeet Jul 10 '19 at 14:14
  • I have debugged and the value of key is wc.DownloadString(dlink); – Dread415 Jul 10 '19 at 14:17
  • Instead of `Dow.DownloadFile(key, path)`, use `Dow.DownloadFile(dlink, path)` – NoName Jul 10 '19 at 14:18
  • I get the file but its corrupt or unreadable. My theory is it downloaded the text and didnt download off the link on pastebin – Dread415 Jul 10 '19 at 14:21
  • No, the value of key isn't wc.DownloadString(dlink); - it's the *result* of that method call. Have you looked at what the **actual value** is in the debugger? – Jon Skeet Jul 10 '19 at 14:31
  • Idk how to do that cause after i run the debugger it stops itself in its tracks and pops up the error message/exeption unhandled shown above – Dread415 Jul 10 '19 at 14:53

2 Answers2

0

I think what's happening is that you try to download the entire website as a file and not downloading the file linked in your pastebin content (proof here).

Maybe there is a way to obtain the link, like: parsing the html of the website and reading the content from a specific html tag or, if existing, using the pastebin api (I will check on that one now. There is a pastebin api. Maybe take a look at this)


Since the api isn't helping you out very much, here is some code to parse HTML from a website: WebClient client = new WebClient(); String htmlCode = client.DownloadString("https://pastebin.com/raw/dnfHuGAK");

This allows you to get the string inside the paste.


This will be your final change to your code and should fix your problem

    String pname = "Fredysploit_v2";
    String dlink = "https://pastebin.com/raw/dnfHuGAK"; 
    //^ changed the download link to the raw paste so you can extract your link
    string title = @"Title ";
    Console.Title = pname + " Bootstrapper";

    Console.ForegroundColor = ConsoleColor.Blue;
    Console.ForegroundColor = ConsoleColor.Cyan;
    Console.WriteLine(title);
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("Downloading new Files...");
    WebClient wc = new WebClient();
    string key = wc.DownloadString(dlink);
    string path = @"Update\" + pname + ".exe";
    System.Net.WebClient Dow = new WebClient();
    string patch = (@"Update");
    Directory.CreateDirectory(patch);
    Dow.DownloadFile(key, path);
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine(pname + " Downloaded | Updated!");
    Console.WriteLine($"Now open { patch } and Run { pname }.exe");
    //^ since you are using String.Format(), make use of it :)
    Console.ReadKey();
JieBaef
  • 122
  • 1
  • 11
  • missclick on keyboard, cant fix "enter code here" tho – JieBaef Jul 10 '19 at 14:28
  • https://github.com/nikibobi/pastebin-csharp maybe check this library out and see if it helps you parsing the pastebin content you need – JieBaef Jul 10 '19 at 14:32
  • No need for any of that - just use https://pastebin.com/raw/V5NcE09n rather than https://pastebin.com/V5NcE09n. Although it seems like a very dodgy way of doing an update... – Jon Skeet Jul 10 '19 at 14:32
  • I agree. I totally forgot about the raw post. – JieBaef Jul 10 '19 at 14:34
  • it is getting a bit more confused looking at this – Dread415 Jul 10 '19 at 14:39
  • I dont really think the api will help me much because it mainly creates pastes – Dread415 Jul 10 '19 at 14:51
  • @Dread415 this is your key's value https://pastebin.com/Qfdur6GZ which causes your code to fail and throw an exception – JieBaef Jul 10 '19 at 15:10
  • @JieBäf what do i do with this? – Dread415 Jul 10 '19 at 15:11
  • you dont do anything with the paste i send you besides knowing what your key's value is. I'll update my answer to make clear where to change something in your code – JieBaef Jul 10 '19 at 15:15
  • Try out the code, I am currently at work so I won't test out downloading files which I don't know anything about – JieBaef Jul 10 '19 at 15:20
  • But i have to say, its pretty sloppy to download the file that way. Why don't you directly include the link inside the pastebin content into your code to reduce unnecessary connections which will lower your programs performance – JieBaef Jul 10 '19 at 15:24
  • oh and you can make a better/cleaner use of your string.format (= $""), I'll add that one to the code and mark the other line of code which i changed @Dread415 – JieBaef Jul 10 '19 at 15:35
  • since you had another problem with the code and me not being able respond under other's answers, I will take another look at it once I'm home (in about 50-60 min) @Dread415 The error you posted seems like its trying to write to directory/file which has been named – JieBaef Jul 10 '19 at 15:58
0

The problem is you are getting the entire page of HTML form pastebin not the URL you are looking for. As @Jon Skeet mentioned in comments, try using https://pastebin.com/raw/V5NcE09n as dlink so it shows as follows:

String dlink = "https://pastebin.com/raw/V5NcE09n";

The updated code solution is below:

String pname = "Fredysploit_v2";
String dlink = "https://pastebin.com/raw/V5NcE09n";
string title = @"Title ";
Console.Title = pname + " Bootstrapper";

Console.ForegroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(title);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading new Files...");
WebClient wc = new WebClient();
string key = wc.DownloadString(dlink);
string path = @"Update\" + pname + ".exe";
System.Net.WebClient Dow = new WebClient();
string patch = (@"Update");
Directory.CreateDirectory(patch);

Dow.DownloadFile(key, path);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(pname + " Downloaded | Updated!");
Console.WriteLine($"Now open " + patch + " and Run " + pname + ".exe");
Console.ReadKey();
ivcubr
  • 1,988
  • 9
  • 20
  • 28
  • There is another Problem... https://i.imgur.com/BXmxLSZ.png – Dread415 Jul 10 '19 at 15:49
  • @Dread415 Is that exception on `Dow.DownloadFile(key, path);`? I have valid values on that line for. When I run it I get `key = https://cdn.discordapp.com/attachments/414163402328375296/598508978095259649/Fredysploit_v2.exe` and `path = Update\Fredysploit_v2.exe`. Add a `Console.WriteLine` to print out each of those values and see what you have at that point – ivcubr Jul 10 '19 at 15:56
  • ok i did Console.Writeline(key); and i got the html code for the page – Dread415 Jul 10 '19 at 16:01
  • nvm i did change it – Dread415 Jul 10 '19 at 16:03
  • @Dread415 I think so, you were downloading the entire HTML page, but if you add the `/raw/` to the URL pastebin will give you just the URL – ivcubr Jul 10 '19 at 16:04
  • i got the samge output u got – Dread415 Jul 10 '19 at 16:06
  • @Dread415 Good, glad to help. Please upvote/accept answers that are helpful to you – ivcubr Jul 10 '19 at 16:09