Zum Inhalt springen

[C#] Files aus Array hochladen


Empfohlene Beiträge

Geschrieben

Hey,

okay, ich sthee nun vor meiner letzten Hürde :)

Ich hole mir mit einem openFileDialog den Pfad zu einem bestimmten Ordner, lese dann den Ordner + Unterordner ein und schmeiß ihn in ein Array:


                    string[] filePaths = Directory.GetFiles(pathToFolder, "*.*", SearchOption.AllDirectories);

                    Array files = filePaths.ToArray();

pathToFolder wird gefüllt durch:

        private void btnSetDirectory_Click(object sender, EventArgs e)

        {

            openFileDialog1.ShowDialog();


            pathToSetupPHP = openFileDialog1.FileNames[0].ToString();

            pathToFolder = Path.GetDirectoryName(pathToSetupPHP).ToString();

        }

Wie kriege ich nun sämtliche Dateien auf den FTP gekloppt? Einer meiner Versuche:

       private void btnStart_Click(object sender, EventArgs e)

        {

            try

            {

                if (MySQLSuccess == true && FTPSuccess == true && pathToSetupPHP != "" && pathToFolder != "")

                {

                    progressBar.Value = 0;

                    btnMySQLCheck.Enabled = false;

                    btnMySQLReset.Enabled = false;

                    btnFTPCheck.Enabled = false;

                    btnFTPReset.Enabled = false;


                    string[] filePaths = Directory.GetFiles(pathToFolder, "*.*", SearchOption.AllDirectories);

                    Array files = filePaths.ToArray();

                    //Array files = Directory.GetFileSystemEntries(pathToFolder);


                    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://" + tbFTPHost.Text + "/" + filePaths);


                    if (cbPassiveMode.Checked == true)

                    {

                        request.UsePassive = true;

                    }

                    else if (cbPassiveMode.Checked == false)

                    {

                        request.UsePassive = false;

                    }


                    if (cbKeepAlive.Checked == true)

                    {

                        request.KeepAlive = true;

                    }

                    else if (cbKeepAlive.Checked == false)

                    {

                        request.KeepAlive = false;

                    }


                    if (cbUseBinary.Checked == true)

                    {

                        request.UseBinary = true;

                    }

                    else if (cbUseBinary.Checked == false)

                    {

                        request.UseBinary = false;

                    }


                    request.Method = WebRequestMethods.Ftp.UploadFile;

                    request.Credentials = new NetworkCredential(tbFTPUsername.Text, tbFTPPassword.Text);

                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();


                    // dateien auf 100 für progressbar

                    // uploading


                    request.Abort();

                    response.Close();


                }

                else if (MySQLSuccess == false && FTPSuccess == true)

                {

                    // Please make sql test first

                    MessageBox.Show("Please make the SQL-Test first!", "Slow down ;)", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                else if (MySQLSuccess == true && FTPSuccess == false)

                {

                    // please make ftp test first

                    MessageBox.Show("Please make the FTP-Test first!", "Slow down ;)", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                else if (MySQLSuccess == false && FTPSuccess == false)

                {

                    MessageBox.Show("Please check FTP and MySQL first!", "Slow down ;)", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                else if (pathToFolder == "" || pathToSetupPHP == "")

                {

                    MessageBox.Show("Set the extracted Directory first!", "Slow down ;)", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                else

                {

                    MessageBox.Show("Something somewhere went terribly wrong...", "Woha!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

            }

            catch (Exception ex)

            {

                rtbLog.Text += ex.Message.ToString();

            }

        }

Danke und liebe Grüße

SeToY

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...