Problem with plugin im making

Discussion in 'Plugin Development' started by tommycake50, Sep 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    tommycake50

    so my question is this when i try to download a plugin file with the plugin i am developing the console says java.io.FileNotFoundException: /plugins (Permission denied) presumably this is the error from when i try to write the file to the /plugins directory so how would i get the required permission to download that file?
    i kinda need this plugin because my internet is crappy and i am changing hosts so i need a plugin to download the crap so i hope i get an answer.
    source
    Code:
    package me.tommycake50.filedownloader;
     
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class filedownloader extends JavaPlugin{
        public Plugin filedownloader;
        Logger logger = Logger.getLogger("Minecraft");
       
        public void onEnable(){
            PluginDescriptionFile pdffile = this.getDescription();
            logger.info(pdffile.getName() + " Has been enabled!");
        }
        public void onDisable(){
            PluginDescriptionFile pdffile = this.getDescription();
            logger.info(pdffile.getName() + "Has been disabled");
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args){
            Player player = (Player) sender;
            if(CommandLabel.equalsIgnoreCase("dl") && player.isOp() && args.length == 1){
                try {
                    URL url = new URL(args[0]);
                   
                    URLConnection conn;
                    conn = url.openConnection();
                    DataInputStream stream = new  DataInputStream(conn.getInputStream());
                    byte[] filedata = new byte[conn.getContentLength()];
                   
                    for (int x = 0; x < filedata.length; x++) {
                        filedata[x] = stream.readByte();
                }
                    stream.close();
                    FileOutputStream fos = new FileOutputStream(new File("/plugins/"));
                    fos.write(filedata);
                    fos.close();
                } catch (MalformedURLException e) {
                    player.sendMessage("MalformedURLException");
                    e.printStackTrace();
                } catch (IOException e) {
                    player.sendMessage("error while dl'ing the file");
                    e.printStackTrace();
                }
            }
            return false;
           
        }
    }
    
     
  2. Offline

    andf54

    No, this is plugin development. This is where people come if they need help with making new plugins.
     
  3. Offline

    tommycake50

    and this is a plugin im making to download the plugin files :3
    and i'll put the source to prove it

    bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
    Zidkon and andf54 like this.
  4. Offline

    Sagacious_Zed Bukkit Docs

  5. Offline

    tommycake50

  6. Offline

    APlusMalware

    Do you have the folder path correct? Have you tried writing to other folders?
     
  7. Offline

    tommycake50

    im positive the file the plugins are in is /plugins

    full stacktrace
    Code:
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:581)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.ServerConnection.b(SourceFile:35)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:807)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:825)
    12.09 01:11:27 [Server] SEVERE at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:878)
    12.09 01:11:27 [Server] SEVERE at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:492)
    12.09 01:11:27 [Server] SEVERE at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    12.09 01:11:27 [Server] SEVERE at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    12.09 01:11:27 [Server] SEVERE at me.tommy2ndacc.filedownloader.filedownloader.onCommand(filedownloader.java:48)
    12.09 01:11:27 [Server] SEVERE at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
    12.09 01:11:27 [Server] SEVERE at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    12.09 01:11:27 [Server] SEVERE at java.io.FileOutputStream.open(Native Method)
    12.09 01:11:27 [Server] SEVERE java.io.FileNotFoundException: /plugins (Permission denied)
    i know what it means but i dont know how to solve it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  8. Offline

    APlusMalware

    You need to have an actual file name and remove the leading forward slash, ex. "plugins/FileName.jar".
     
Thread Status:
Not open for further replies.

Share This Page