-1

hello how can I replace our ftp to our server on driver address in this code?

string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp");

for example:

string[] filePaths = Directory.GetFiles(@"our ftp address", "*.bmp");

the first code is running well but second isnt working!? tnx

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Atena
  • 1
  • 1
  • You are using `ftp://` ? If so you cannot use `Directory.GetFiles()` See [How to: List Directory Contents with FTP](http://msdn.microsoft.com/en-us/library/ms229716.aspx) – Alex K. Oct 27 '14 at 13:18
  • possible duplicate of [How to List Directory Contents with FTP in C#?](http://stackoverflow.com/questions/3298922/how-to-list-directory-contents-with-ftp-in-c) – CodeCaster Oct 27 '14 at 14:29

2 Answers2

1

Example from http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx DisplayFileFromServer(your bmp file)

`public static bool DisplayFileFromServer(Uri serverUri)
{
    // The serverUri parameter should start with the ftp:// scheme. 
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    WebClient request = new WebClient();
    request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
    try 
    {
        byte [] newFileData = request.DownloadData (serverUri.ToString());
        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        Console.WriteLine(fileString);
    }
    catch (WebException e)
    {
        Console.WriteLine(e.ToString());
    }
    return true;
}`
Neil
  • 32
  • 3
0

This short program will list the files and directories from an FTP server using the ListDirectoryDetails method. There's also a ListDirectory method that will list only the names.

using System;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            WebRequest ftp =  FtpWebRequest.Create("ftp://ftp.ed.ac.uk/");
            ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            using (WebResponse rsp = ftp.GetResponse())
            {
                using (StreamReader reader = new StreamReader(rsp.GetResponseStream()))
                {
                    Console.WriteLine(reader.ReadToEnd());
                }
            }
        }
    }
}
BlueMonkMN
  • 25,079
  • 9
  • 80
  • 146