Esempio n. 1
0
        internal SftpSynchronizer(string username, string password, SecurityIdentifier userSid)
        {
            ConnectionInfo connectionInfo = new ConnectionInfo(Settings.ProfileServerAddress, Settings.ProfileServerPort, username, new PasswordAuthenticationMethod(username, password));

            if (Settings.HostKey == string.Empty)
            {
                remote = new RemoteContext(connectionInfo);
            }
            else
            {
                byte[] expectedHostKey = Convert.FromBase64String(Settings.HostKey);
                remote = new RemoteContext(connectionInfo, expectedHostKey);
            }
            remote.Connect();

            this.username       = username;
            this.userSid        = userSid.Value;
            serverBaseDirectory = Settings.ProfileServerBaseDirectory;

            SyncInformation syncInformation    = GetSyncInformation();
            bool            remoteProfileExist = syncInformation.Status != SyncInformation.SyncStatus.DoesNotExist;
            string          localProfilePath   = GetLocalProfilePath(username, password, userSid, remoteProfileExist);
            string          remoteProfilePath  = string.Format("{0}/{1}", serverBaseDirectory, username);

            uploadExclusionList = CreateUploadExclusionList(localProfilePath);
            localProfile        = new LocalDirectory(localProfilePath, uploadExclusionList, username);
            remoteProfile       = new RemoteDirectory(remote, remoteProfilePath, syncInformation.SidInLastHost, this.userSid);
        }
Esempio n. 2
0
        internal void SaveSyncInformation(SyncInformation.SyncStatus status)
        {
            string syncInformationDirectoryPath = string.Format("{0}/{1}", serverBaseDirectory, SYNC_INFORMATION_DIRECTORY);
            string syncInformationPath          = string.Format("{0}/{1}/{2}", serverBaseDirectory, SYNC_INFORMATION_DIRECTORY, username);

            if (!remote.sftp.Exists(syncInformationDirectoryPath))
            {
                remote.sftp.CreateDirectory(syncInformationDirectoryPath);
                remote.sftp.ChangePermissions(syncInformationDirectoryPath, 01777);
            }

            using (var stream = remote.sftp.OpenWrite(syncInformationPath))
            {
                var syncInformation = new SyncInformation(status, Environment.MachineName, userSid);
                syncInformation.Save(stream);
            }
        }