我有一個使用 .NET 4.6.1 框架的 C# exe。我從 C exe 啟動這個 exe,因為這是要求。它以前有效,但突然停止按應有的方式作業。我用 5 個引數啟動 exe。我檢查了接收到的引數的值和長度,當 C# exe 接收到它時,它們似乎都是正確的,但是當涉及到DownloadFile方法時,它似乎拋出了例外。另一方面,如果我對值進行硬編碼或在命令提示符下運行 exe 并將引數傳遞給它似乎作業正常。一旦從 C exe 啟動它,它就會將其從堆疊跟蹤寫入我正在將其列印到的日志中
用戶名是:abc unname 長度是:3| 密碼為:abc@123 密碼長度為:7| 補丁下載路徑為:\10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip FileToDownload 長度為:60| 補丁下載到路徑為:E:\Test\Patch.zip localDestinationFilePath 長度為:17
System.Net.WebException
在 IPMPlusAlternatePatchDownloader.IPMPlusPatchDownloader.DownloadPFile(String userName, String密碼,字串 FileToDownload,字串 localDestinationFilePath)
這是我正在使用的代碼
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);
}
這是我硬編碼值而不是從引數中獲取它們時的樣子
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);
}
用戶名是:abc unname 長度是:3| 密碼為:abc@123 密碼長度為:7| 補丁下載路徑為:\10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip FileToDownload 長度為:60| 補丁下載到路徑為:E:\Test\Patch.zip localDestinationFilePath 長度為:17
下載P檔案EOF
長度是引數的長度,而不是我硬編碼的值。
這是下載檔案后的螢屏截圖,但由于某種原因,它只是

我為此使用了 Visual Studio 2017。我在此處添加代碼時已從代碼中洗掉了日志陳述句,以使其看起來更清晰。
有想法該怎么解決這個嗎?
uj5u.com熱心網友回復:
您收到的引數包含路徑,該路徑"patch download from path is: \10.1.1.119\Backup_share\patch testing\Skype-8.81.0.268.zip"似乎不包含“\”字符的字符的任何轉義序列,這可能是您收到例外的原因。在每個應該修復它的“\”字符后添加一個額外的“\”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458729.html
下一篇:MVCC#中的多個復選框選擇
