2013-06-12 204 views
-1

我嘗試將文件上傳到FTP服務器,我不斷收到「引發WebException無法連接到遠程服務器530未登錄」上傳文件到FTP C#

劑量人知道如何解決這個問題? ütryied禁用我的防火牆,但它沒有任何效果

/* Create an FTP Request */ 
       FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(ftpurl + "/" + remoteFile); 
       /* Log in to the FTP Server with the User Name and Password Provided */ 
       ftpRequest.Credentials = new NetworkCredential(ftpuser, ftppassword,ftpurl); 
       /* When in doubt, use these options */ 
       ftpRequest.UseBinary = true; 
       ftpRequest.UsePassive = true; 
       ftpRequest.KeepAlive = true; 
       /* Specify the Type of FTP Request */ 
       ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; 
       /* Establish Return Communication with the FTP Server */ 
       Stream ftpStream = ftpRequest.GetRequestStream(); 
       /* Open a File Stream to Read the File for Upload */ 
       FileStream localFileStream = new FileStream(localFile, FileMode.Create); 
       /* Buffer for the Downloaded Data */ 
       byte[] byteBuffer = new byte[bufferSize]; 
       int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); 
       /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */ 

       { 
        while (bytesSent != 0) 
        { 
         ftpStream.Write(byteBuffer, 0, bytesSent); 
         bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); 
        } 
       } 

       /* Resource Cleanup */ 
       localFileStream.Close(); 
       ftpStream.Close(); 
       ftpRequest = null; 
+0

您驗證了用戶/ pw/url的內容嗎? – 2013-06-12 10:05:51

+0

**未登錄** - 提供正確的憑證。 – CodeCaster

回答

0

NetworkCredential似乎是錯誤的。第三個參數設置域(請參閱:NetworkCredential Constructor)。嘗試將其更改爲:

ftpRequest.Credentials = new NetworkCredential(ftpuser, ftppassword); 
+0

我嘗試了它現在我得到anoter webexception,只是說系統錯誤 – user1839169

+0

@dna - 你可以使用所有三個,請參閱http://msdn.microsoft.com/en-us/library/cytcd70k.aspx – 2013-06-12 10:04:30

+0

@DarthVader確定你可以,但使用FTP網址作爲域名顯然是錯誤的 – dna