Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


C#
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();
             }
         }
       
        }
Posted
Updated 18-Jun-12 10:04am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900