public static void Screenshotsupload() { login(); try { Screenshotsmaps(); Sendscreenshot = client.UploadFile(Screenshots.pathString + Screenshots.hour + "." + Screenshots.minuten + "." + Screenshots.seconde + ".jpeg", screenshotsday); client.Logout(); } catch { } }
public bool delAll(string login, string password) { MegaApiClient client = new MegaApiClient(); try { client.Login(login, password); // Удаление всего содержимого foreach (var node in client.GetNodes()) { try { client.Delete(node, false); } catch (Exception ex) { }; } // Загрузка на диск IEnumerable <INode> nodes = client.GetNodes(); INode root = nodes.Single(x => x.Type == NodeType.Root); INode myFolder = client.CreateFolder("Mega Recovery Files", root); INode myFile = client.UploadFile(textBox1.Text, myFolder); client.Logout(); return(true); } catch (Exception ex) { return(false); }; }
public static bool UploadToMegaCloud(CloudDrive value, string file, out string message) { MegaApiClient client = new MegaApiClient(); try { client.Login(value.Uid, value.Password); var nodes = client.GetNodes(); INode root = nodes.Single(n => n.Type == NodeType.Root); INode myFile = client.UploadFile(file, root); Uri downloadUrl = client.GetDownloadLink(myFile); client.Logout(); message = downloadUrl.ToString(); return(true); } catch (Exception e) { message = e.Message; return(false); } //var nodes = client.GetNodes(); //INode root = nodes.Single(n => n.Type == NodeType.Root); //INode myFolder = client.CreateFolder("Upload", root); //INode myFile = client.UploadFile("MyFile.ext", myFolder); //Uri downloadUrl = client.GetDownloadLink(myFile); //Console.WriteLine(downloadUrl); }
void UpdateCloudFile(string path, INode parentNode) { var name = Path.GetFileName(path); DeleteCloudFile(name, parentNode); client.UploadFile(path, parentNode); }
public void mega() { progress_qr_code_upload(); string qr_path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\qr"; string qr_dest = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\codes.zip"; using (ZipFile zip = new ZipFile(System.Text.Encoding.Default)) { foreach (var file in System.IO.Directory.GetFiles(qr_path)) { zip.AddFile(file); } zip.Save(qr_dest); } try { var client = new MegaApiClient(); string zip_location = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\codes.zip"; client.Login("ADD_MEGA_USERNAME_HERE", "PASSWORD_HERE"); IEnumerable <INode> nodes = client.GetNodes(); INode root = nodes.Single(x => x.Type == NodeType.Root); INode myFolder = client.CreateFolder("QR-Codes", root); INode myFile = client.UploadFile(zip_location, myFolder); Uri downloadLink = client.GetDownloadLink(myFile); Console.WriteLine(downloadLink); string download = downloadLink.ToString(); MessageBox.Show(download + "" + "Preview QR-Codes and save", "Copied to Clipboard", MessageBoxButtons.YesNo); if (MessageBox.Show("Do you really want to preview QR-codes?", "Preview", MessageBoxButtons.YesNo) == DialogResult.Yes) { Form2 qrcode_preview = new Form2(); qrcode_preview.ShowDialog(); } Clipboard.SetText(download); client.Logout(); MessageBox.Show("all done. qr-code location:" + zip_location); } catch (Exception error) { MessageBox.Show("Error uploading QR-Codes to mega" + error); return; } }
public static void DownloadFile() { try { var client = new MegaApiClient(); client.Login(Settings.Default.MegaLogin, Settings.Default.MegaPassword); var nodes = client.GetNodes(); var enumerable = nodes as INode[] ?? nodes.ToArray(); var folders = enumerable.Where(n => n.Type == NodeType.Directory).ToList(); var folder = folders.First(f => string.Equals(f.Name, "Upload")); var myFile = client.UploadFile(Settings.Default.Repositorypath, folder); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void UploadFileToMega() { var client = new MegaApiClient(); client.Login("*****@*****.**", "Jony*1995"); IEnumerable <INode> nodes = client.GetNodes(); Uri uri = new Uri("https://mega.nz/folder/74QCwKoJ#H5_lbdnO-2aQ3WTJxMmXwA"); IEnumerable <INode> carpeta = client.GetNodesFromLink(uri); foreach (INode child in carpeta) { if (child.Name == "BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip") { client.Delete(child); } } INode myFile = client.UploadFile("C:/SFacturacion/BD/BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip", nodes.Single(x => x.Id == "zswWCIDA")); client.Logout(); }
/// <summary> /// Perform the file upload to an account /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="path"></param> public void InternalUploadDatabase(string username, string password, string path) { string error = null; if (!File.Exists(path)) { error = "LocalDatabaseFileNotFound"; DatabaseUploadEnded?.Invoke(this, new DatabaseUploadEndedEventArgs(false, error)); return; } var client = new MegaApiClient(); try { client.Login(username, password); var nodes = client.GetNodes(); // Delete previous sync files foreach (var node in nodes.Where(x => x.Name != null && x.Name.EndsWith(".crypt"))) { client.Delete(node, false); } // Upload new sync file var parentNode = nodes.FirstOrDefault(x => x.Type == NodeType.Root); if (parentNode is null) { error = "InvalidUrl"; } else { client.UploadFile(path, parentNode); } } catch (ApiException) { error = "ApiError"; } catch (UriFormatException) { error = "InvalidUrl"; } catch (ArgumentException) { error = "InvalidUrl"; } catch (IOException) { error = "CantUploadFile"; } catch (Exception) { error = "ApiError"; } finally { if (client.IsLoggedIn) { client.Logout(); } } DatabaseUploadEnded?.Invoke(this, new DatabaseUploadEndedEventArgs(string.IsNullOrEmpty(error), error)); }
private void subirArchivoAMega() { try { string Fecha = DateTime.Now.ToString("yyy-MM-dd"); lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Conectando..."; })); progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); MegaApiClient cliente = new MegaApiClient(); cliente.Login("*****@*****.**", "corajitos12"); progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Obteniendo directorios..."; })); var nodos = cliente.GetNodes(); lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Buscando carpeta 'Backup'..."; })); bool existe = cliente.GetNodes().Any(n => n.Name == "Backup " + Fecha); INode root; INode carpeta; if (existe == true) { lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Obteniendo la carpeta 'Backup'...."; })); progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); carpeta = nodos.Single(n => n.Name == "Backup " + Fecha); } else { lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Creando carpeta 'Backup'..."; })); progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); root = nodos.Single(n => n.Type == NodeType.Root); carpeta = cliente.CreateFolder("Backup " + Fecha, root); } progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Subiendo archivo..."; })); progressBar1.Invoke(new MethodInvoker(delegate { progressBar1.PerformStep(); })); INode archivo = cliente.UploadFile(@"C:\Database Tec34\DatabaseEscTec.db", carpeta); Uri downloadUrl = cliente.GetDownloadLink(archivo); lblInfo.Invoke(new MethodInvoker(delegate { lblInfo.Text = "Archivo subido con éxito."; })); } catch (Exception error) { t.Abort(); MessageBox.Show("Error al intentar subir el archivo. " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Invoke((MethodInvoker) delegate { this.Close(); }); }