2015-06-25 57 views
0
string uploadPath = "http://10.126.64.230/home/pi/Videos/"; 
WebClient webclient = new WebClient(); 
CredentialCache cc = new CredentialCache(); 
Uri uri = new Uri("http://10.126.64.230/pi"); 
NetworkCredential nc = new NetworkCredential(); 
nc.Domain = "root"; 
nc.UserName = "pi"; 
nc.Password = "posix"; 
cc.Add(
    uri, 
"NTLM", 
nc); 
webclient.Credentials = cc; 
//System.Text.Encoding.ASCII.GetString(responseArray); 
bool cntrl = System.IO.File.Exists(uploadPath + this.FuplVideo.FileName); 

if (cntrl) 
{ 
    // fileName = uploadPath + this.FuplVideo.FileName + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + ext; 
    // webclient.UploadFile(uploadPath, "POST", fullFilePath); 
} 
else 
{ 
    webclient.UploadFile(uploadPath, "POST", fullFilePath); 
} 

我嘗試將文件發送到與LAN連接的計算機。但我試試這個代碼與不同版本的域名,我System.Net.Sockets.SocketException在使用webclient時

「System.Net.Sockets.SocketException沒有因爲目標 機的連接被拒絕」每次

錯誤。你建議我什麼?

+0

如何使用System.IO讀取httpPath? bool cntrl = System.IO.File.Exists(uploadPath + this.FuplVideo.FileName)?如果它的netqork使用UNC:\\ 10.126.64.230 \ home \ pi \ Videos \ –

+0

我將在我修復此錯誤後將其刪除。 –

回答

0

目標機器有可能在您正在訪問的端口上有防火牆規則。我猜測這是端口80.嘗試遠程登錄到遠程服務器,看看你是否有連接。如果您無法連接,那麼它必須是防火牆問題

+0

我可以將文件複製到機器,但無法通過代碼訪問。 –

+0

轉到命令行並嘗試:c:/ telnet 10.126.64.230 80 –

+0

沒有什麼。 –