部署 Web 服务 FTP C# 中出错



我试图使用网络服务下载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?

提前致谢

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

最新更新