Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# FTP
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();
             }
         }
       
        }
Posted 18-Jun-12 9:52am
Edited 18-Jun-12 10:04am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 Nirav Prabtani 343
1 OriginalGriff 207
2 Mika Wendelius 185
3 CPallini 179
4 Sergey Alexandrovich Kryukov 176
0 Nirav Prabtani 398
1 OriginalGriff 292
2 Sergey Alexandrovich Kryukov 251
3 Mika Wendelius 185
4 Abhinav S 180


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 18 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100