2013-06-12 203 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