无法识别URI前缀-从Windows上的C#应用​​连接到Unix服务器 [英] URI prefix is not recognized - connecting to unix server from c# app on windows

查看:84
本文介绍了无法识别URI前缀-从Windows上的C#应用​​连接到Unix服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要使用我在c#中内置的ftp客户端来从unix ftp服务器中获取文件,我当前的ftp客户端可以与Windows类型的ftp服务器一起很好地工作,但是尝试连接到Unix服务器时存在问题被我的ftp客户端检测到,提示无法识别URI前缀.",这是我的ftp客户端:
//uri是/uriString:servername.domain.com//我尝试放置ftp.一开始只是没有帮助.
//端口为:21


Wanting to use my ftp client that I built in c# to grab files from a unix ftp server, my current ftp client works well with windows type of an ftp server, but trying to connect to a Unix server there is an issue being detected by my ftp client suggesting "The URI prefix is not recognized.", here is my ftp client:
//The uri is/uriString: servername.domain.com // I tried placing an ftp. at the begining but no help.
//port is: 21


private static string[] GetFilesToftp(string WildCard, string uriString, string etServer, string etUser, string etPassword)
        {
         string ReturnStr = "";
         string ftpServer = etServer; 
         string ftpUser = etUser; 
         string ftpPassword = etPassword; 
         
         FtpWebRequest request = null;
         WebResponse response = null;
         Stream responseStream = null;

         try
         {
             request = WebRequest.Create(@uriString + WildCard) as FtpWebRequest;
             //Specify we are Listing a directory
             request.Method = WebRequestMethods.Ftp.ListDirectory;
             request.Credentials = new NetworkCredential(ftpUser, ftpPassword);

             //Get a reponse
             //response = request.GetResponse();
             response = (FtpWebResponse)request.GetResponse();

             responseStream = response.GetResponseStream();

             //Convert the response to a string
             int ch;
             while ((ch = responseStream.ReadByte()) != -1)
                 ReturnStr = ReturnStr + Convert.ToChar(ch);

             //split the string by new line
             string[] sep = { "\r\n" };
             string[] Files = ReturnStr.Split(sep, StringSplitOptions.RemoveEmptyEntries);

             return Files;
         }
         catch (WebException wex)
         {

             string Message = (wex.Message != null) ? wex.Message.ToString() : "";
             if (wex.Message.StartsWith("The remote server returned an error: (550) File unavailable"))
             {
               return null;
             }
             else if (wex.Message.StartsWith("The remote server returned an error: (530) Not logged in"))
             {
               return null;
             }
             else
             {
                 throw wex;
             }
            
         }
         finally
         {
             if (responseStream != null)
             {
                 responseStream.Flush();
                 responseStream.Close();
                 responseStream.Dispose();
             }
             if (response != null)
             {
                 response.Close();
             }
         }
       
        }

推荐答案

我能够登录到Unix服务器,我只需要定义服务器位置:ftp://servername.domain. com:port/现在,我需要知道如何在此服务器上进行伪装,然后开始从该位置下载文件.预先感谢.
I was able to log on to the Unix server, I only had to define the server location: ftp://servername.domain.com:port/ now I need to know how I can chage firectory on this server then start downloading files from that location. Thanks in advance.


这篇关于无法识别URI前缀-从Windows上的C#应用​​连接到Unix服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆