Ejemplo n.º 1
0
        public async Task DownloadItemAsync(DirectoryItem item, string localPath)
        {
            using (WebClient ftpClient = new MiWebClient())
            {
                ftpClient.Credentials = new NetworkCredential(server.User, server.Password);
                ftpClient.Proxy       = null;
                var _path = Path.GetDirectoryName(localPath);
                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }
                try
                {
                    await ftpClient.DownloadFileTaskAsync(item.Uri, localPath);

                    if (item.DateCreated != DateTime.Parse("01/01/0001 0:00:00"))
                    {
                        File.SetLastWriteTime(localPath, item.DateCreated);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                //await ftpClient.DownloadFileTaskAsync(item.Uri, @localPath);
            }
        }
Ejemplo n.º 2
0
        private void grilla_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != -1)
            {
                if (e.RowIndex != -1)
                {
                    if (this.grilla.Columns[e.ColumnIndex].Name == "Descargar")
                    {
                        string artista  = grilla.Rows[e.RowIndex].Cells[2].Value.ToString();
                        string titulo   = grilla.Rows[e.RowIndex].Cells[3].Value.ToString();
                        string duracion = grilla.Rows[e.RowIndex].Cells[4].Value.ToString();

                        string urlParte1 = grilla.Rows[e.RowIndex].Cells[0].Value.ToString();
                        string urlParte2 = grilla.Rows[e.RowIndex].Cells[1].Value.ToString();
                        string urlLista  = "https://y.mp3xdi.org/yd/" + urlParte1 + "/" + urlParte2 + ".mp3";

                        string link = urlLista;

                        Uri realLink = new Uri(link);

                        MiWebClient wc = new MiWebClient();
                        listaWC.Add(wc);

                        wc.artista  = artista;
                        wc.titulo   = titulo;
                        wc.duracion = duracion;
                        wc.fila     = listaWC.Count - 1;

                        if (txtRutaDescarga.Text != "")
                        {
                            wc.DownloadFileAsync(new Uri(link), txtRutaDescarga.Text + "/" + artista + "-" + titulo + ".mp3");
                        }
                        else
                        {
                            string path = Application.StartupPath;

                            wc.DownloadFileAsync(new Uri(link), path + "/" + artista + "-" + titulo + ".mp3");
                        }

                        //wc.progreso += new DownloadProgressChangedEventHandler(cargando);
                        wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(cargando);
                        wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(descargado);

                        grilla_descargas.Rows.Add(wc.artista, titulo, wc.duracion);
                    }
                }
            }
        }