开发者

Windows Azure - Load Data via FTP in ASP.NET App

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜