system.net.webexception:远程服务器返回错误:(530)未登录。 [英] system.net.webexception: The remote server returned an error: (530) Not logged in.
本文介绍了system.net.webexception:远程服务器返回错误:(530)未登录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我试图将文件上传到FTP服务器,下面是我的代码:我收到错误system.net.webexception :远程服务器返回错误:(530)未登录。
hi Guys ,
I am trying to uplaod the file into the FTP server , below is my code : i am getting error as"system.net.webexception: The remote server returned an error: (530) Not logged in."
if (fileupload.HasFile)
{ //create the path to save the file to
string fileName = "/" + fileupload.FileName;
//Is the file too big to upload?
int fileSize = fileupload.PostedFile.ContentLength;
string maxsize = ConfigurationManager.AppSettings["MaxFileSize"];
bool sflag = Convert.ToBoolean(ConfigurationManager.AppSettings["RestrictFileSize"]);
if (sflag)
{
if (fileSize > (Convert.ToInt32(maxsize) * 1048576))
{
UploadStatusLabel.Text = "Filesize is too large. Maximum file size permitted is " + maxsize + "MB";
}
else
{
////save the file to our local path
string foldername = string.Empty;
string ftpUser = string.Empty;
string ftpPassword = string.Empty;
foldername = ConfigurationManager.AppSettings["FilePath"];
ftpUser = ConfigurationManager.AppSettings["FTPUser"];
ftpPassword = ConfigurationManager.AppSettings["FTPPassword"];
string userdomain = ConfigurationManager.AppSettings["FTPDomain"];
string filename = fileupload.PostedFile.FileName;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(foldername)+ fileName);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(ftpUser.Normalize(), ftpPassword.Normalize(), userdomain.Normalize());
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(filename);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
推荐答案
http://social.msdn.microsoft.com/Forums / en-US / 043af65b-9adc-4ea7-bdee-afc153bd81ed /--remote-server-returned-an-error-530-not-logged-in [ ^ ]
查看链接..希望你能找到一些方法。
http://social.msdn.microsoft.com/Forums/en-US/043af65b-9adc-4ea7-bdee-afc153bd81ed/the-remote-server-returned-an-error-530-not-logged-in[^]
check the link..hope you will get some way to try.
这篇关于system.net.webexception:远程服务器返回错误:(530)未登录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文