【发布时间】: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