I have a C# exe that uses .NET 4.6.1 framework. I launch this exe from a C exe as that is the requirement. It worked before but it suddenly stopped working the way it was supposed to.
I launch the exe with 5 parameters. I checked the value and the length of the arguments received, they all appear to be correct when the C# exe receives it but when it comes to the DownloadFile
method it seems to throw an exception.
On the other hand, if I hardcode the values or run the exe in the command prompt and pass the arguments to it seems to work fine.
As soon as launch it from the C exe it writes this from the stack trace to the log that I'm printing it into
username is: abc uname length is: 3| password is: abc@123 pass length is: 7| patch download from path is: \10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip FileToDownload length is: 60| patch download to path is: E:\Test\Patch.zip localDestinationFilePath length is: 17
System.Net.WebException Exception in DownloadPFile( at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName) at IPMPlusAlternatePatchDownloader.IPMPlusPatchDownloader.DownloadPFile(String userName, String password, String FileToDownload, String localDestinationFilePath)
Here is the code I'm using
static void Main(string[] args)
{
PacthDownload.DownloadPFile(args[1], args[2], args[3], args[4]);
}
private void DownloadFileShareAndFTP(string userName, string password, string FileToDownload, string localDestinationFilePath)
{
WebClient client = new WebClient();
client.Credentials = new NetworkCredential(userName, password);
client.DownloadFile(FileToDownload, localDestinationFilePath);
}
Here is how it looks when I hardcode the values instead of getting them from the arguments
static void Main(string[] args)
{
PacthDownload.DownloadFileShareAndFTP("abc", "abc@123",@"\\10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip", @"E:\Test\Patch.zip");
//PacthDownload.DownloadPFile(args[1], args[2], args[3], args[4]);
}
private void DownloadFileShareAndFTP(string userName, string password, string FileToDownload, string localDestinationFilePath)
{
WebClient client = new WebClient();
client.Credentials = new NetworkCredential(userName, password);
client.DownloadFile(FileToDownload, localDestinationFilePath);
}
username is: abc uname length is: 3| password is: abc@123 pass length is: 7| patch download from path is: \10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip FileToDownload length is: 60| patch download to path is: E:\Test\Patch.zip localDestinationFilePath length is: 17
DownloadPFile EOF
the length is those of the arguments, not the values I hardcoded.
Here is a screenshot of how it looks like once the file is downloaded but for some reason it only
I'm using visual studio 2017 for this. I have removed the log statements from the code while adding it here so as to make it look cleaner.
Any ideas on how to fix this?
CodePudding user response:
The Argument your receive which contains the path this one "patch download from path is: \10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip"
doesn't seem to contain any escape sequences for the characters for the "\" character which is probably why you're receiving the exception. Add an extra "\" after every "\" character that should fix it.