[英]How do I fix System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect
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. 我正在尝试为程序创建引导程序,并且错误“ System.Net.WebException:'文件名,目录名或卷标语法不正确”不断弹出。
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". 我期望结果将文件下载为文本,而该文本是pastebin上的链接,但是实际结果是“ System.Net.WebException:'文件名,目录名或卷标语法不正确”。
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 ). 我认为发生的事情是您尝试将整个网站作为文件下载,而不是下载在pastebin内容中链接的文件( 此处提供证明 )。
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) 也许有一种获取链接的方法,例如:解析网站的html并从特定的html标记中读取内容,或者如果存在的话,使用pastebin api(我将对此进行检查。现在有一个pastebin api (也许看看这个)
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 ");
由于该API不能为您提供很大帮助,因此这里有一些代码可以用来解析网站中的HTML:
WebClient client = new WebClient(); String htmlCode = client.DownloadString(" https://pastebin.com/raw/dnfHuGAK ");
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();
The problem is you are getting the entire page of HTML form pastebin not the URL you are looking for. 问题是您正在获取HTML表单pastebin的整个页面,而不是您要查找的URL。 As @Jon Skeet mentioned in comments, try using
https://pastebin.com/raw/V5NcE09n
as dlink
so it shows as follows: 就像@Jon Skeet在评论中提到的那样,请尝试将
https://pastebin.com/raw/V5NcE09n
用作dlink
以便其显示如下:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.