Ejemplo n.º 1
0
        public LocationResultSet send()
        {
            FTPUtils ftputils = new FTPUtils((FTPCredentialsConfig)config);

            ftputils.Progress += progressHandler;
            LocationResultSet result = ftputils.sendFile();

            return(result);
        }
Ejemplo n.º 2
0
        private void onSaveErrorHandler(string message)
        {
            LocationResultSet result = new LocationResultSet();

            result.wasSuccessful = false;
            result.errorMessage  = message;
            results.Add(result);
            setupForNewSave();
        }
Ejemplo n.º 3
0
        public LocationResultSet send()
        {
            LocationResultSet result = new LocationResultSet();

            result.path = config.locationPath;
            try
            {
                string[] path     = config.sourcePath.Split('\\');
                string   filename = path[path.Length - 1];
                string[] temp     = filename.Split('.'); //pernei to extension apo to sourcepath kai na to kanei append sto location
                if (config.fnamePrefix != null)
                {
                    config.locationPath += "_" + config.fnamePrefix;
                }
                config.locationPath = config.locationPath + "." + temp[temp.Length - 1];
                temp = config.locationPath.Split('\\');
                string directorypath = "";
                for (int i = 0; i < temp.Length - 1; i++)
                {
                    directorypath += temp[i] + "\\";
                }
                directorypath = directorypath.Substring(0, directorypath.Length - 1);
                System.IO.Directory.CreateDirectory(directorypath); //dimiourgei ta directory sto path an den iparxoun

                //COPY
                Copy();
                if (cancelFlag == true)
                {
                    result.wasSuccessful = false;
                    result.errorMessage  = "Copy was cancelled";
                    return(result);
                }

                //akiro afto to command File.Delete(config.locationPath); //kamia fora prokalei unothorized access exception den mporw na katalavw me poia logiki
                result.wasSuccessful = true;

                /*
                 * File.Move(config.sourcePath, config.locationPath+temp[temp.Length-1]);
                 * //Microsoft.VisualBasic.FileIO.FileSystem.MoveFile("sorceFile.ext", "destFile.ext", Microsoft.VisualBasic.FileIO.UIOption.AllDialogs);
                 * //to panw tha ekane move to arxeio me to klasiko move dialog twn windows
                 * result.wasSuccessful = true;*/
            }
            catch (Exception ex)
            {
                result.wasSuccessful = false;
                result.errorMessage  = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 4
0
        private LocationResultSet Upload()
        {
            try {
                var uploadTask = UploadTask();

                uploadTask.Wait();
                Console.WriteLine(res.wasSuccessful);
                return(res);
            }catch (Exception ex)
            {
                res = new LocationResultSet();
                res.wasSuccessful = false;
            }
            return(res);
        }
Ejemplo n.º 5
0
        private async Task UploadTask()
        {
            Console.WriteLine(config.LocalFilePath);
            string content = File.ReadAllText(config.LocalFilePath);

            using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                dbx = new DropboxClient(config.Token);
                var updated = await dbx.Files.UploadAsync(
                    config.Path + "/" + config.FileName,
                    WriteMode.Overwrite.Instance,
                    body : mem);

                res = new LocationResultSet();
                res.wasSuccessful = updated.IsFile;
                res.path          = config.Path;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sto config sourcePath einai tou server kai to locationPath prepei na einai directory
        /// </summary>
        public LocationResultSet getFile()
        {
            LocationResultSet result = new LocationResultSet();

            try
            {
                session = new Session();

                session.FileTransferProgress += sessionFileTransferProgress;
                checkFingerprint();

                session.Open(sessionOptions);

                session.GetFiles(config.sourcePath, config.locationPath).Check();

                result.wasSuccessful = true;
                result.path          = config.locationPath;
            }
            catch (Exception ex)
            {
                if (firstCheck && ex.Message.StartsWith("Host key does not match configured key"))
                {
                    compareFingerprint();
                    firstCheck = false;
                    sendFile();
                }
                else
                {
                    result.wasSuccessful = false;
                    result.errorMessage  = ex.Message;
                }
            }
            finally
            {
                session.Dispose();
            }
            return(result);
        }
Ejemplo n.º 7
0
 private void onSaveCompleteHandler(LocationResultSet result)
 {
     results.Add(result);
     setupForNewSave();
 }
Ejemplo n.º 8
0
 private void onSaveComplete(LocationResultSet result)
 {
     SaveComplete?.Invoke(result);
 }
Ejemplo n.º 9
0
 public void onSaveComplete(LocationResultSet result)
 {
     Console.WriteLine("Save Completed!");
 }
Ejemplo n.º 10
0
        /// <summary>
        /// To location path prepei na einai directory
        /// Location path tis morfis /home/user/filename
        /// </summary>
        public LocationResultSet sendFile()
        {
            LocationResultSet result = new LocationResultSet();

            try
            {
                session = new Session();

                session.FileTransferProgress += sessionFileTransferProgress;
                checkFingerprint();

                string[] locationinfo = StringUtils.splitPath(config.locationPath);
                string[] sourceinfo   = StringUtils.splitPath(config.sourcePath);
                string   ext          = StringUtils.getExtension(sourceinfo[1]);

                session.Open(sessionOptions);


                //mporeis na peirakseis ta dikaiwmata tou arxeiou
                TransferOptions transferOptions = new TransferOptions();
                transferOptions.TransferMode = TransferMode.Binary;

                TransferOperationResult transferResult;
                transferResult = session.PutFiles(config.sourcePath, locationinfo[0], false, transferOptions);

                transferResult.Check(); //Prepei na kanei throw exception se periptwsi fail iparxei kai transferResult.isSuccess den to exw testarei
                try
                {
                    session.ExecuteCommand("rm " + locationinfo[0] + locationinfo[1] + ext);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                session.MoveFile(locationinfo[0] + sourceinfo[1], locationinfo[0] + locationinfo[1] + ext);

                /* ama ithela na xeiristw results apo transfers polaplwn arxeiwn
                 * foreach (TransferEventArgs transfer in transferResult.Transfers)
                 * {
                 *  Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                 * }*/

                result.wasSuccessful = true;
                result.path          = locationinfo[0] + locationinfo[1] + ext;
            }
            catch (Exception ex)
            {
                if (firstCheck && ex.Message.StartsWith("Host key does not match configured key"))
                {
                    compareFingerprint();
                    firstCheck = false;
                    sendFile();
                }
                else
                {
                    result.wasSuccessful = false;
                    result.errorMessage  = ex.Message;
                }
            }
            finally
            {
                session.Dispose();
            }
            return(result);
        }