Click here to Skip to main content
Sign Up to vote bad
good
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:52
Edited 18 Jun '12 - 10:04


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

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 159
2 Richard MacCutchan 150
3 Maciej Los 136
4 Tadit Dash 110
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,917
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,125


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 18 Jun 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid