FTP System.Net.WebException: 远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/farmwang/article/details/81604018

原因没有创建文件夹的路径

  try
            {
                Connect(path);
                reqFTP.Method = WRMethods;
                response =(FtpWebResponse) reqFTP.GetResponse();
                if(response==null)
                {
                    Log.Error("[FTPTool][GetFileList][GetResponse] is NULL");
                    return null;
                }
                else
                {
                    Log.Info("[response data is: ]"+response.StatusCode.ToString() + " " + response.StatusDescription.ToString());
                }

                Log.Info("[FTPTool][GetResponse] status: {0}", response.StatusDescription);
                reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);//中文文件名
                string line = reader.ReadLine();
                while (line != null)
                {
                    Log.Info("[Line ReaderLine ]"+line);
                    result.Append(line);
                    result.Append("\n");
                    line = reader.ReadLine();
                   
                }
                // to remove the trailing ' ' 
                result.Remove(result.ToString().LastIndexOf('\n'), 1);

                return result.ToString().Split('\n');
            }
            catch (Exception ex)
            {
                Log.Error("[FtpTools][GetFileList]" + ex.ToString());

                Log.Info("[Ex Message]"+ex.Message);
                Log.Info("[Ex InnerException]" + ex.InnerException);
                Log.Info("[Ex HResult]" + ex.HResult.ToString());
                Log.Info("[Ex Message]" + ex.Source);
                Log.Info("[Contenttype]" + response.ContentType);
                Log.Info("[ExitMessage]" + response.ExitMessage);

                downloadFiles = null;
                return downloadFiles;
            }

如果FTP没有该路径C#会报错,报Exception

猜你喜欢

转载自blog.csdn.net/farmwang/article/details/81604018