Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
foreach (string f in Directory.GetFiles(("ftp://me@localhost/" + newFolder)))

C#
Error: Given Path is not supported.

newFolder consists of sub directories and files.
Posted
v2

You can't just get ftp listings from the Directory class: you have to set up an FTP connection first:
C#
            FTPGetListing(@"Username", "Password", "ftp.Images.MyDomain.com");
...
        private void FTPGetListing(string user, string password, string ftpURL)
            {
            string strConnect = string.Format("ftp://{0}", ftpURL);
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(strConnect);
            ftp.Credentials = new NetworkCredential(user, password);
            ftp.KeepAlive = false;
            ftp.Method = WebRequestMethods.Ftp.DownloadFile;
            ftp.UseBinary = true;
            ftp.Proxy = null;
            ftp.UsePassive = false;
            List<string> folders, files;
            FTPGetFolder(ftp, @"\", out folders, out files);
            // ...
            }
        private void FTPGetFolder(FtpWebRequest request, string baseFolder, out List<string> folders, out List<string> files)
            {
            request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            string listing = reader.ReadToEnd();
            folders = new List<string>();
            files = new List<string>();
            string[] lines = listing.Split('\n', '\r');
            foreach (string line in lines)
                {
                ...
                }
            reader.Close();
            response.Close();
            }


[Edit]
Extra tags "</string></string>" removed.
[/Edit]
 
Share this answer
 
v2
As the as message says, you cannot list files from a FTP path.
This might help: How to: List Directory Contents with FTP[^]
 
Share this answer
 
I think you can't use Directory class for FTP, use FtpWebRequest instead.

FtpWebRequest Class[^]
 
Share this answer
 
v2

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