Windows Azure - 通过 FTP 在 ASP.NET 应用程序中加载数据
我正在尝试将数据存储在 Windows azure 本地,我之前通过 FTP 下载了这些数据。
我像这样下载文件(在我的本地计算机上工作):
string[] files = GetFileList("/config/shared/");
foreach (string file in files)
{
Download(file, "/config/shared/", _myConfigsStorage.RootPath + "userUpload\\shared\\");
}
但是在第一行出现错误:
未将对象引用设置为对象的实例。
这里是 GetFileList-Method:
private static string[] GetFileList(string remoteDirSoruceFiles)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(_ftpHostUrl + remoteDirSoruceFiles));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(_ftpUserName, _ftpUserPwd);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
}
catch (Exception)
{
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
downloadFiles = null;
return downloadFiles;
}
}
我不明白这种情况下的错误消息。听起来,GetFileList 返回一个空值。
Windows Azure 上是否可以通过 FtpWebRequest 进行 FTP 连接,或者我是否需要配置防火墙或其他东西。还有什么?
有什么建议吗?
此致, 帕特里克
I am trying to store data local on windows azure, which I downloaded before via FTP.
I download the file like this (works on my local machine):
string[] files = GetFileList("/config/shared/");
foreach (string file in files)
{
Download(file, "/config/shared/", _myConfigsStorage.RootPath + "userUpload\\shared\\");
}
But at the first line an error occures:
Object reference not set to an instance of an object.
Here the GetFileList-Method:
private static string[] GetFileList(string remoteDirSoruceFiles)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(_ftpHostUrl + remoteDirSoruceFiles));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(_ftpUserName, _ftpUserPwd);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
}
catch (Exception)
{
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
downloadFiles = null;
return downloadFiles;
}
}
I dont understand this error message in this context. It sounds, like the GetFileList returns a null-value.
Are FTP-Connections via FtpWebRequest possible at Windows Azure, or have I to configure the firewall or sth. else?
Any suggestions?
Best Regards,
Patrick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论