Download php url

Anaconda

New member
Joined
Jun 26, 2018
Messages
3
Programming Experience
1-3
Hello,
Sorry, but I do not speak English very well ...
Under visual studio 2017 in C # I created a site vacuum. I want to download a php file in the form http://urldusite.com/download.php?type=hd&id_project=1142 "How can I get the download url, the size ...
This url is protected by a login and a password that of course I own. Apparently, we have to download the source code in php with ftp, but now my knowledge is exhausted ...
Do we have to go through FTP and if so, how?
I really have no idea if anyone can help me ...
Have a nice day.
 
In simple cases you can use a WebClient to download from HTTP or FTP URLs, e.g.
using (var client = new WebClient())
{
    client.Credentials = new NetworkCredential(userName, password);
    client.DownloadFile(sourceUrl, localFilePath);
}

In that case, the file at 'sourceUrl' will be downloaded to 'localFilePath' on your machine. You should read a bit about the WebClient class first and see what other methods and properties it has.

In more complex cases, you can use an FtpWebRequest. Let's not go into that unless we need to though.
 
Sorry, but this answer gives nothing, I have already tried ... the answer is equal to null.
Nobody has another solution?
 
I have already tried ... the answer is equal to null.
If you'd already tried something and it didn't work then you should have provided details in your initial post. Also, what you're saying doesn't make sense because there is no "answer". WebClient.DownloadFile doesn't return anything so it can't return null. Perhaps you should provide a FULl and CLEAR explanation of exactly what you did and exactly what happened.
 
If you'd already tried something and it didn't work then you should have provided details in your initial post. Also, what you're saying doesn't make sense because there is no "answer". WebClient.DownloadFile doesn't return anything so it can't return null. Perhaps you should provide a FULl and CLEAR explanation of exactly what you did and exactly what happened.

Thank you for your answer. Sorry, I mis explained myself ...
Here, what I did for the moment ...
C#:
        Boolean Download(string UrlDownload, object startPoint)
        {
            try
            {
                int startPointInt = Convert.ToInt32(startPoint);
                DownloadRequest = (HttpWebRequest)WebRequest.Create(UrlDownload);
                DownloadRequest.AddRange(startPointInt);
                if (!string.IsNullOrEmpty(Identifiant)) { DownloadRequest.Credentials = new NetworkCredential(Identifiant, Password); }
                else { DownloadRequest.Credentials = CredentialCache.DefaultCredentials; }
                try
                {
                    GridDownloadsC11.StyleInfo.Text = "Demande informations de téléchargement...";
                    DownloadReponse = (HttpWebResponse)DownloadRequest.GetResponse();
                    Int64 FileSize = DownloadReponse.ContentLength;
                    string content = DownloadReponse.ContentType; ;
                    strResponse = DownloadReponse.GetResponseStream();
                    if (startPointInt == 0) { strLocal = new FileStream(FichierDownload, FileMode.Create, FileAccess.Write, FileShare.None); }
                    else { strLocal = new FileStream(FichierDownload, FileMode.Append, FileAccess.Write, FileShare.None); }
                    int bytesSize = 0;
                    byte[] downBuffer = new byte[2048];
                    while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
                    {
                        strLocal.Write(downBuffer, 0, bytesSize);
                        GridDownloads.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, FileSize + startPointInt });
                        if (goPause == true) { break; }
                    }
                    strResponse.Close();
                    strLocal.Close();
                    TimerDownload.Stop();
                    TimerDebit.Stop();
                    TimerImage.Stop();
                    if (goPause == false)
                    {
                        long result = new FileInfo(FichierDownload).Length;
                        if (result == FileSize + startPointInt) { return false; }//Erreur=false
                        else { return true; }//Erreur=true
                    }
                }
                catch {}
            }
            finally
            {
            }
            return false;
        }
I also create a function for searching the file name but the answer is equal to zero
C#:
        public static string GetFilename(string Url)
        {
            string Filename = "";
            try
            {
                DownloadRequest = (HttpWebRequest)WebRequest.Create(Url);
                if (Identifiant != null & Password != null) DownloadRequest.Credentials = new NetworkCredential(Identifiant, Password);
                DownloadRequest.Method = WebRequestMethods.Http.Head;
                using (DownloadReponse = (HttpWebResponse)DownloadRequest.GetResponse())
                {
                    string disposition = DownloadReponse.Headers["Content-Disposition"];// S'il y a un en-tête Content-Disposition, on l'utilise
                    if (!string.IsNullOrEmpty(disposition))
                    {
                        string fileNamePart = disposition.Split(';').Select(s => s.Trim()).FirstOrDefault(s => s.StartsWith("filename="));
                        if (!string.IsNullOrEmpty(fileNamePart))
                        {
                            string NomFichier = fileNamePart.Substring("filename=".Length);
                            NomFichier = NomFichier.Replace("\"", "");
                            return NomFichier;
                        }
                    }
                    string responseUri = DownloadReponse.ResponseUri.AbsoluteUri;// Sinon on utilise l'URI de la réponse (éventuellement redirigée)
                    Filename=Uri.UnescapeDataString(Path.GetFileName(responseUri));
                    DownloadReponse.Close();
                }
            }
            catch { }
            return Filename;
        }
Same for the file size:
C#:
        public static Int64 GetFileSize(string Url)
        {
            Int64 FileSize = 0;
            try
            {
                DownloadRequest = (HttpWebRequest)WebRequest.Create(Url);
                if (!string.IsNullOrEmpty(Identifiant)) { DownloadRequest.Credentials = new NetworkCredential(Identifiant, Password); }
                else { DownloadRequest.Credentials = CredentialCache.DefaultCredentials; }
                //DownloadRequest.Timeout = 5000;
                DownloadReponse = (HttpWebResponse)DownloadRequest.GetResponse();
                FileSize=DownloadReponse.ContentLength;
                DownloadReponse.Close();
                return FileSize;
            }
            catch { }
            return FileSize;
        }
 
Back
Top Bottom