vendredi 16 mars 2018

403 error while trying to download a exe from my web server

I keep getting a 403 error and I tried everything to get it right for my auto updater for something that I'm making which is supposed to get a .exe and replace the old .exe with the new updated one...

package cyara;

import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Controller {
public Label latest;
public Label verision;
private String version = "1.0";

    public void downloadLatest(ActionEvent actionEvent) {
        verision.setText("Current Updater Version " + version);
        latest.setText("Downloading Files");

                String url = "https://www.kadepcgames.com/downloads/cyara/b-0001/latest/Cyara.exe";

                try {
                    latest.setText("Connecting to www.kadepcgames.com/downloads/cyara/b-0001/latest/Cyara.exe");
                    downloadUsingNIO(url, "/Program Files/Cyara/Cyara.exe");
                    latest.setText("Trying to download the backup");
                    downloadUsingStream(url, "/Program Files/Cyara/CyaraBackup.exe");
                } catch (IOException e) {
                    latest.setText("Download Failed!");
                    e.printStackTrace();
                }
            }

            private static void downloadUsingStream(String urlStr, String file) throws IOException{
                URL url = new URL(urlStr);
                URLConnection uc;
                uc = url.openConnection();
                uc.addRequestProperty("User-Agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
                BufferedInputStream bis = new BufferedInputStream(url.openStream());
                FileOutputStream fis = new FileOutputStream(file);
                byte[] buffer = new byte[1024];
                int count=0;
                while((count = bis.read(buffer,0,1024)) != -1)
                {
                    fis.write(buffer, 0, count);
                }
                fis.close();
                bis.close();
            }

            private static void downloadUsingNIO(String urlStr, String file) throws IOException {
                URL url = new URL(urlStr);
                URLConnection uc;
                uc = url.openConnection();
                uc.addRequestProperty("User-Agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
                ReadableByteChannel rbc = Channels.newChannel(url.openStream());
                FileOutputStream fos = new FileOutputStream(file);
                fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
                fos.close();
                rbc.close();
            }

        }

And I'm getting the java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.example.com/downloads/cyara/b-0001/latest/Cyara.exe error Mostly tried tutorials but none of them worked for me. So really the only thing I thought was the permissions (which I checked) and still even after setting them to 777 no luck at all! I'm really getting tired of this.




Aucun commentaire:

Enregistrer un commentaire