Место общения программистов C#
Anonymous
FtpWebRequest возвращает «Удаленный сервер возвратил ошибку: (530) Не выполнен вход»
Сообщение
Anonymous » 28 янв 2026, 04:03
Я получаю эту ошибку: «Удаленный сервер возвратил ошибку: (530) Не выполнен вход». при загрузке файла с помощью FtpWebRequest.
Ошибка возникает только тогда, когда я переношу файлы по пути с подпапками, в противном случае все работает нормально.
При загрузке больших файлов размером от 5 до 10 МБ время ожидания истекает.
Код: Выделить всё
void FtpTransfer(string siteName, string portNumber, string ftpUser, string ftpPassword, string destPath)
{
FtpWebRequest request;
DateTime now = DateTime.Now;
string now_string =
(now.Year).ToString()
+ "_" +
(now.Month).ToString("0#")
+ "_" +
(now.Day).ToString("0#");
foreach (object item in listBox1.Items)
{
string srcFile = item.ToString();
lblSource.Text = srcFile;
Uri uri = new Uri(srcFile);
string destFile = srcFile.Replace(lblPath.Text, "").Replace("\\\\", "\\").Replace("\\", "/").Replace("www/","");
Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
int timeout = int.Parse(oConfig.AppSettings.Settings["TimeOut"].Value);
if (siteName == "mysite1.co.in" || siteName == "sd1.mysite2.net")
destFile = "ftp://" + siteName + ":" + portNumber + "/" + siteName + "/_test" + destFile; //error here
else
destFile = "ftp://" + siteName + ":" + portNumber + "/" + siteName + destFile; //no error
lblDestn.Text = destFile;
request = (FtpWebRequest)WebRequest.Create(destFile);
request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
request.Timeout = 6000;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@srcFile);
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();
string path = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
System.IO.StreamWriter w = System.IO.File.AppendText(path + "\\log_" + now_string + ".txt");
w.WriteLine(DateTime.Now.ToString("yyy-MM-dd HH:mm:ss")
+ " "
+ srcFile
+ " "
+ destFile
+ " "
+ response.StatusDescription);
w.Close();
response.Close();
}
Подробнее здесь:
https://stackoverflow.com/questions/142 ... -logged-in
1769562210
Anonymous
Я получаю эту ошибку: «Удаленный сервер возвратил ошибку: (530) Не выполнен вход». при загрузке файла с помощью FtpWebRequest. [list] [*]Ошибка возникает только тогда, когда я переношу файлы по пути с подпапками, в противном случае все работает нормально. [*]При загрузке больших файлов размером от 5 до 10 МБ время ожидания истекает. [code]void FtpTransfer(string siteName, string portNumber, string ftpUser, string ftpPassword, string destPath) { FtpWebRequest request; DateTime now = DateTime.Now; string now_string = (now.Year).ToString() + "_" + (now.Month).ToString("0#") + "_" + (now.Day).ToString("0#"); foreach (object item in listBox1.Items) { string srcFile = item.ToString(); lblSource.Text = srcFile; Uri uri = new Uri(srcFile); string destFile = srcFile.Replace(lblPath.Text, "").Replace("\\\\", "\\").Replace("\\", "/").Replace("www/",""); Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); int timeout = int.Parse(oConfig.AppSettings.Settings["TimeOut"].Value); if (siteName == "mysite1.co.in" || siteName == "sd1.mysite2.net") destFile = "ftp://" + siteName + ":" + portNumber + "/" + siteName + "/_test" + destFile; //error here else destFile = "ftp://" + siteName + ":" + portNumber + "/" + siteName + destFile; //no error lblDestn.Text = destFile; request = (FtpWebRequest)WebRequest.Create(destFile); request.Credentials = new NetworkCredential(ftpUser, ftpPassword); request.Timeout = 6000; request.Method = WebRequestMethods.Ftp.UploadFile; request.UsePassive = true; request.UseBinary = true; request.KeepAlive = true; // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(@srcFile); 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(); string path = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]); System.IO.StreamWriter w = System.IO.File.AppendText(path + "\\log_" + now_string + ".txt"); w.WriteLine(DateTime.Now.ToString("yyy-MM-dd HH:mm:ss") + " " + srcFile + " " + destFile + " " + response.StatusDescription); w.Close(); response.Close(); } [/code] [/list] Подробнее здесь: [url]https://stackoverflow.com/questions/14279817/ftpwebrequest-returns-the-remote-server-returned-an-error-530-not-logged-in[/url]