Esempio n. 1
0
 private void fileList_Drop(object sender, DragEventArgs e)
 {
     try {
         FTPLibrary ftpLib = new FTPLibrary(userNameBox.Text, passwordBox.Password, isSecureConnection);
         int count = 0;
         string log = "";
         if (e.Data is System.Windows.DataObject &&
             ((System.Windows.DataObject)e.Data).ContainsFileDropList()) {
             foreach (string filePath in ((System.Windows.DataObject)e.Data).GetFileDropList()) {
                 double size = ftpLib.GetFTPSize(ftpBox.Text + "/" + System.IO.Path.GetFileName(filePath));
                 if (size > 0) {
                     MessageBoxResult r;
                     r = MessageBox.Show("The file: '" + System.IO.Path.GetFileName(filePath) +
                         "' already exist on this server, do you want to overwrite?", "File exist",
                         MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                     if (r == MessageBoxResult.Yes) {
                         log = ftpLib.Upload(ftpBox.Text + "/" + System.IO.Path.GetFileName(filePath), filePath);
                         count++;
                     }
                 }
                 else {
                     log = ftpLib.Upload(ftpBox.Text + "/" + System.IO.Path.GetFileName(filePath), filePath);
                     fileList.Items.Add(System.IO.Path.GetFileName(filePath));
                     count++;
                 }
             }
         }
         if (log.StartsWith("Error"))
             ShowStatus(log);
         else
             ShowStatus("Succesfully uploaded " + count + " files at '" + ftpBox.Text + "'");
     }
     catch (Exception ex){
         ShowStatus(ex.Message);
     }
 }
Esempio n. 2
0
        //Save files in the background
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Get arguments
            string[] tmp = (e.Argument as string[]);

            //Attempt to save file
            try {
                //Save the file
                StreamWriter w = new StreamWriter(tmp[0]);
                w.Write(tmp[1]);
                w.Close();
            }
            catch { //Set result status code on failure
                e.Result = "Error! Unable to save file: " + System.IO.Path.GetFileName(tmp[0]);
            }
            try {
                //Save the file
                if (tmp[2] == "true") {
                    //Attempts to upload file
                    string check = "";
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        FTPLibrary ftpLib = new FTPLibrary(userNameBox.Text, passwordBox.Password, isSecureConnection);
                        check = ftpLib.Upload("ftp://" + tmp[3], tmp[0]);
                    }));

                    //Set result status code
                    if (!check.StartsWith("Error"))
                        e.Result = "Document published: (" + System.IO.Path.GetFileName(tmp[0]) + ")";
                    else {
                        e.Result = "Failed to publish document! Reason: (" + check.Substring(7) + ")";
                    }
                }
                else {
                    //Set result status code
                    e.Result = "Document saved: (" + System.IO.Path.GetFileName(tmp[0]) + ")";
                }
            }
            catch (Exception ex){ //Set result status code on failure
                e.Result = "Error! Unable to publish file: " + System.IO.Path.GetFileName(tmp[0]) + ", Reason: (" + ex.Message + ")";
            }
        }