Wątek przeniesiony 2016-03-25 15:04 z C# i .NET przez ŁF.

Błąd przy tworzeniu folderu na serwerze ftp

0

Witam, mam problem z programem który ma za zadanie utworzyć folder na serwerze ftp o nazwie komputera z którego została aplikacja uruchomiona, odczytanie nazwy działa, ale wyrzuca błąd w momencie w którym chcę odczytać status z serwera.
kod mojej klasy:

 class Program
    {
       
        static String folder_name = (Environment.MachineName);
        static String FTP_SERVER = "ftp://miloszge.cba.pl";

        static void Main(string[] args)
        {
            make_folder();
        }

        static void make_folder()
        {
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTP_SERVER + folder_name);
            request.Credentials = new NetworkCredential("[email protected]", "subsys");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;

            request.Method = WebRequestMethods.Ftp.MakeDirectory;

           using (var resp = (FtpWebResponse)request.GetResponse())
           {
               Console.WriteLine(resp.StatusCode);
               Console.WriteLine(folder_name + " was maked");
            }
            Console.ReadKey();
        }
    }

Wyrzucany jest błąd:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote name could not be resolved: 'miloszge.cba.plmil0sz-pc'

Co tutaj można naprawić? Oczywiście System.Net został załączony.

0

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote name could not be resolved: 'miloszge.cba.plmil0sz-pc'

1

A przeczytałeś wyjątek?

The remote name could not be resolved: 'miloszge.cba.plmil0sz-pc'

A może uważasz, że uri miloszge.cba.plmil0sz-pc jest prawidłowe?

0

Mam kolejny problem, teraz już powyższy kod działa, ale chciałem dodać warunek, że jeżeli istnieje już taki folder program ma wyświetlić tekst.
kod teraz wygląda tak:

 static String folder_name = ("/" + Environment.MachineName);
        static String FTP_SERVER = "ftp://miloszge.cba.pl";
static void make_folder()
        {
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTP_SERVER + folder_name);
            request.Credentials = new NetworkCredential("[email protected]", "subsys");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;

            if (Directory.Exists(FTP_SERVER + "/" + folder_name))
            {
                Console.WriteLine("Directory Exist");
            }

            else
            {
                request.Method = WebRequestMethods.Ftp.MakeDirectory;

                using (var resp = (FtpWebResponse)request.GetResponse())
                {
                    Console.WriteLine(resp.StatusCode);
                    Console.WriteLine(folder_name + " has been created");
                }

            }
            

            Console.ReadKey();
        }

Przy warunku else program działa dobrze i tworzy folder, ale przy warunku if w linijce od "using (var resp = ((...)" serwer zwraca błąd 500, brak dostępu do pliku. Jak to mogę naprawić?

0

Klasa Directory nie służy do działania na ftp. Użyj klasy, która służy do tego. Zapewne jest to klasa, której używasz do utworzenia katalogu...

1 użytkowników online, w tym zalogowanych: 0, gości: 1