【问题标题】:Error in Deploy webservice FTP C#部署 web 服务 FTP C# 中的错误
【发布时间】:2023-05-26 22:40:01
【问题描述】:

我正在尝试使用 webservice 下载 FTP 服务器内的文件。

[WebMethod]
    public string BrowseFileSimplify(string FileName, string varlocaldirectory)
    {

        Regex regex = new Regex(@"[a-zA-Z_-]+?\.[a-zA-Z]{1,5}$");
        Match match = regex.Match(FileName);
        if (match.Success)
        {
            try
            {


                string inputfilepath = varlocaldirectory + "\\" + FileName;

                using (WebClient request = new WebClient())
                {
                    request.Credentials = new NetworkCredential(UserName, Password);
                    byte[] fileData = request.DownloadData(uri+FileName);

                    using (FileStream file = File.Create(inputfilepath))
                    {
                        file.Write(fileData, 0, fileData.Length);
                        file.Close();
                    }
                    return "Download Success";
                }
            }
            catch (Exception ex)
            {
                return "Problem with " + ex.Message; //Error en la aplicacion
            }
        }
        else
        {
            return "Error with file format"; //Error en el formato del archivo
        }

    }

当我使用 VisualStudio 执行时它工作正常,它返回 “下载成功”,但是当我上传到 web 时它返回:“错误:无法连接到远程服务器"

我需要在 web.config 中添加一些代码吗?

提前致谢

【问题讨论】:

    标签: c# asp.net web-services ftp


    【解决方案1】:

    可能是网络问题。需要了解更多有关托管环境的信息才能确定。您通常会通过登录服务器并尝试 ping/telnet 到目标 ftp 服务器并从那里开始进行故障排除。

    【讨论】:

    • 这是主机,我尝试使用另一个主机,如 azure,它成功了。谢谢。
    最近更新 更多