コード例 #1
0
        void synchroniseAllFiles()
        {
            Console.WriteLine("Upload files started...");

            ServicePointManager.ServerCertificateValidationCallback =
                (s, certificate, chain, sslPolicyErrors) => true;

            try
            {
                using (WinSCP.Session session = new WinSCP.Session())
                {
                    session.FileTransferProgress += SessionFileTransferProgress;
                    // Connect
                    session.Open(_sessionOptions);
                    string localDir = _rootPath;

                    WinSCP.SynchronizationResult result = session.SynchronizeDirectories(WinSCP.SynchronizationMode.Remote, localDir, "Ents/Logs", false);

                    if (result.IsSuccess)
                    {
                        Console.WriteLine("Directories successfully synchronised!");
                    }
                    else
                    {
                        for (int i = 0; i < result.Failures.Count; i++)
                        {
                            Console.WriteLine("Error: {0}", result.Failures[i].Message);
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception: {0}, {1}", excp.Message, excp.StackTrace);
            }
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: Rupan/winscp
        private SynchronizationResult ReadSynchronizeDirectories()
        {
            using (Logger.CreateCallstack())
            {
                SynchronizationResult result = new SynchronizationResult();

                using (ElementLogReader groupReader = _reader.WaitForGroupAndCreateLogReader())
                using (RegisterOperationResult(result))
                using (CreateProgressHandler())
                {
                    bool transferIsUpload = false;
                    TransferEventArgs transfer = null;

                    while (groupReader.Read(0))
                    {
                        bool transferWillBeUpload;
                        if ((transferWillBeUpload = groupReader.IsNonEmptyElement(TransferEventArgs.UploadTag)) ||
                            groupReader.IsNonEmptyElement(TransferEventArgs.DownloadTag))
                        {
                            if (transfer != null)
                            {
                                AddSynchronizationTransfer(result, transferIsUpload, transfer);
                            }
                            transfer = TransferEventArgs.Read(groupReader);
                            transferIsUpload = transferWillBeUpload;
                        }
                        else if (groupReader.IsNonEmptyElement(RemovalEventArgs.Tag))
                        {
                            result.AddRemoval(RemovalEventArgs.Read(groupReader));
                        }
                        else if (groupReader.IsNonEmptyElement(ChmodEventArgs.Tag))
                        {
                            if (transfer == null)
                            {
                                throw new InvalidOperationException();
                            }
                            transfer.Chmod = ChmodEventArgs.Read(groupReader);
                        }
                        else if (groupReader.IsNonEmptyElement(TouchEventArgs.Tag))
                        {
                            if (transfer == null)
                            {
                                throw new InvalidOperationException();
                            }
                            transfer.Touch = TouchEventArgs.Read(groupReader);
                        }
                    }

                    if (transfer != null)
                    {
                        AddSynchronizationTransfer(result, transferIsUpload, transfer);
                    }
                }
                return result;
            }
        }
コード例 #3
0
ファイル: Session.cs プロジェクト: Rupan/winscp
 private void AddSynchronizationTransfer(SynchronizationResult result, bool transferIsUpload, TransferEventArgs transfer)
 {
     if (transferIsUpload)
     {
         result.AddUpload(transfer);
     }
     else
     {
         result.AddDownload(transfer);
     }
     RaiseFileTransferredEvent(transfer);
 }