gpt4 book ai didi

c# - FtpWebRequest 返回 "The remote server returned an error: (530) Not logged in"

转载 作者:行者123 更新时间:2023-11-30 18:47:39 25 4
gpt4 key购买 nike

我收到此错误“远程服务器返回错误:(530) 未登录。”使用 FtpWebRequest 上传文件时。

  1. 仅当我将文件传输到具有子文件夹的路径时才会发生错误,否则它会正常工作。
  2. 上传大约 5 到 10 MB 的大文件时,会超时。

    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();
    }

最佳答案

我假设您已经尝试通过标准 FTP 客户端执行相同的操作。如果没有,试试看。然后我会使用 Wireshark 来确保这是来自服务器的响应并验证是否正在发送凭据。验证后,与 FTP 所有者核实并确保服务器配置正确。

关于c# - FtpWebRequest 返回 "The remote server returned an error: (530) Not logged in",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14279817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com