【发布时间】:2018-10-19 23:30:47
【问题描述】:
当我尝试使用 FTP 从 Azure WebJobs 发送文件时,我遇到了 1 个问题。 这会交替抛出“远程服务器返回错误:(530)未登录。”,我的代码在本地主机(在开发计算机上)中运行良好。
我已经阅读了所有这些帖子,但我没有找到方法:
FTPWebRequest 530 Error: Not Logged in issue
FTP The remote server returned an error: (530) Not logged in
Fetching files from FTP server via Azure webjobs
Ftp to external server in azure webjob not working
其他,但我的应用服务中只有 1 个网络作业,并且当作业运行时 CPU 为 30%。 File download from FTP fails only in Azure web app
编辑: 代码制作目录
FtpWebRequest reqFTP = null;
Stream ftpStream = null;
string[] subDirs = directory.Split('/');
string currentDir = publishUrl;
foreach (string subDir in subDirs)
{
try
{
currentDir = currentDir + "/" + subDir;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(currentDir);
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
reqFTP.UseBinary = true;
//reqFTP.UsePassive = true;
//reqFTP.KeepAlive = true;
reqFTP.Credentials = new NetworkCredential(userName, userPWD);
FtpWebResponse response = (FtpWebResponse)await reqFTP.GetResponseAsync();
ftpStream = response.GetResponseStream();
ftpStream.Close();
response.Close();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
//directory already exist I know that is weak but there is no way to check if a folder exist on ftp...
}
}
代码发送文件:
try
{
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential(userName, userPWD);
client.UploadFile(publishUrl, "STOR", localFileName);
return true;
}
}
catch (Exception exception)
{
//Console.Error.Write(exception.Message);
Console.WriteLine(exception.Message);
return false;
}
当我在 Azure WebApp WebJobs 中运行代码时记录(失败): https://pastebin.com/vgTxqT5p
当我在本地机器上运行代码时记录(工作得很好): https://pastebin.com/hBpum8T0
我认为解决方法是使用 WebJobs 应用程序样式,而正常功能没有等待。我将更改我的代码以对我的所有 WebJobs 程序使用 Async Await 方法。
有办法吗? 提前谢谢。
【问题讨论】:
-
向我们展示您的代码和log file。
-
谢谢我已经把我的代码,我要生成日志文件。我也在 Azure 支持上开了一张票。
-
在 WebJobs Azure 上实现日志文件:blogs.msdn.microsoft.com/waws/2017/03/14/…
-
@MartinPrikryl 日志文件已添加。 pastebin.com/vgTxqT5p
-
每个日志中的请求太多,因此很难跟踪。但显然有些请求成功登录,而有些则没有。看起来您在服务器上达到了关于打开连接数的一些限制。您应该咨询服务器管理员。
标签: c# azure ftp azure-webjobs