Exemplo n.º 1
0
        // uploads a file (async)
        public bool UploadFileAsync(TransferFile file, bool showProgress,
                                    Uri remotePath, string localPath, FileTransferCallback callback)
        {
            var files = new List <TransferFile>()
            {
                file
            };

            return(TransferFilesAsync(files, showProgress, remotePath, localPath, callback, false));
        }
Exemplo n.º 2
0
        // locks the server (async)
        private void LockServer(DelegateTransfer callback)
        {
            try
            {
                // create local lockfile
                if (!File.Exists(localPath + lockFile))
                    File.Create(localPath + lockFile);
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                callback(false);
                return;
            }

            // try to upload the lockfile
            TransferFile file = new TransferFile(lockFile);
            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    serverLock = (result == FileTransferResult.Success);
                    callback(serverLock);
                });
        }
Exemplo n.º 3
0
        // downloads and handles the global config file from the ftp server
        private void Init()
        {
            connected = true;

            // set remote path (e.g. "ftp://www.example.com/myFolder")
            remotePath = new Uri(protocol + Settings.Path);

            // set credentials (username, password, passive mode)
            fileTransfer.Client.Credentials = new NetworkCredential(Settings.User, Settings.Password);
            fileTransfer.Client.UsePassive = Settings.Passive;

            // download global config async
            TransferFile file = new TransferFile(globalConfig);
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                // callback of the download
                delegate(FileTransferResult result)
                {
                    if (exit)
                        FireExit();
                    else
                    {
                        // versions object handels global config file if download has been successful
                        if (result == FileTransferResult.Success)
                            versions.Load(localPath + globalConfig);

                        // fire some events
                        ResetInterface();
                    }
                });
        }
Exemplo n.º 4
0
        // downloads global config file and checks new version (async)
        private void DownloadGlobalConfig(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(globalConfig);

            // try to download global config file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    if (result == FileTransferResult.Success)
                        versions.Load(localPath + globalConfig);

                    // check new version number
                    callback(versions.CheckNewVersionNr(ulVersion));
                });
        }
Exemplo n.º 5
0
        // checks if server is locked (async)
        private void CheckLock(DelegateTransfer callback)
        {
            TransferFile file = new TransferFile(lockFile);

            // try to download lock file
            fileTransfer.DownloadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    if (!exit)
                        callback(result == FileTransferResult.Failure);
                    else
                        FireExit();
                });
        }
Exemplo n.º 6
0
        // creates global config and uploads it (async)
        private void UploadGlobalConfig(DelegateTransfer callback)
        {
            // latest update = uploaded version
            versions.LatestUpdate = ulVersion;

            // if uploaded version is a full version
            if (ulFullVersion)
                // latest version = uploaded version
                versions.LatestFullVersion = ulVersion;

            // add uploaded version to version list
            versions.Add(ulVersion, ulFullVersion);

            // save global config to local temp folder
            versions.Save(localPath + globalConfig);

            var file = new TransferFile(globalConfig);

            // try to upload new global config
            fileTransfer.UploadFileAsync(file, false, remotePath, localPath,
                delegate(FileTransferResult result)
                {
                    callback(result == FileTransferResult.Success);
                });
        }