Package jcifs.smb

Examples of jcifs.smb.SmbFile


        }
    }

    private void upgradeToDirectorySmbFile() throws MalformedURLException {
        if (!smbFile.getPath().endsWith("/")) {
            smbFile = new SmbFile(smbFile.getURL() + "/", connection.authentication);
        }
    }
View Full Code Here


            smbFile = new SmbFile(smbFile.getURL() + "/", connection.authentication);
        }
    }

    private void refreshSmbFile() throws MalformedURLException {
        smbFile = new SmbFile(smbFile.getPath(), connection.authentication);
    }
View Full Code Here

    }

    @Override
    public OverthereFile getFile(String hostPath) throws RuntimeIOException {
        try {
            SmbFile smbFile = new SmbFile(encodeAsSmbUrl(hostPath), authentication);
            return new CifsFile(this, smbFile);
        } catch (IOException exc) {
            throw new RuntimeIOException(exc);
        }
    }
View Full Code Here

        NtlmAuthenticator.setDefault(this);
    }

    void run() throws Exception {
        String cmd, prompt;
        SmbFile conn, tmp;
        SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM");
        SimpleDateFormat sdf2 = new SimpleDateFormat("d");
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy h:mm a");
        sdf1.setCalendar(new GregorianCalendar());
        sdf2.setCalendar(new GregorianCalendar());
        sdf3.setCalendar(new GregorianCalendar());

        conn = new SmbFile(start);
        while (true) {
            try {
                if (conn.exists()) {
                    prompt = conn.getName() + "> ";
                } else {
                    System.out.println("error reading " + conn);
                    conn = new SmbFile("smb://");
                    continue;
                }
                System.out.print(prompt);

                cmd = readLine();
                if (cmd.equals("")) {
                    //empty
                } else if (cmd.startsWith("cd")) {
                    int i = cmd.indexOf(' ');
                    String dir;
                    if (i == -1 || (dir = cmd.substring(i).trim()).length() == 0) {
                        conn = new SmbFile("smb://");
                        continue;
                    }
                    tmp = new SmbFile(conn, dir);
                    if (tmp.exists()) {
                        if (tmp.isDirectory()) {
                            conn = tmp;
                        } else {
                            System.out.println(dir + " is not a directory");
                        }
                    } else {
                        System.out.println("no such directory");
                    }
                } else if (cmd.startsWith("ls")) {
                    int i = cmd.indexOf(' ');
                    SmbFile d = conn;
                    String dir, wildcard = "*";
                    if (i != -1 && (dir = cmd.substring(i).trim()).length() != 0) {
                        // there's an argument which could be a directory,
                        // a wildcard, or a directory with a wildcard appended
                        int s = dir.lastIndexOf('/');
                        int a = dir.lastIndexOf('*');
                        int q = dir.lastIndexOf('?');

                        if ((a != -1 && a > s) || (q != -1 && q > s)) {
                            // it's a wildcard
                            if (s == -1) {
                                wildcard = dir;
                                d = conn;
                            } else {
                                wildcard = dir.substring(s + 1);
                                d = new SmbFile(conn, dir.substring(0, s));
                            }
                        } else {
                            d = new SmbFile(conn, dir);
                        }
                    }
                    long t0 = System.currentTimeMillis();
                    SmbFile[] list = d.listFiles(wildcard);
                    t0 = System.currentTimeMillis() - t0;
                    if (list != null) {
                        for (int j = 0; j < list.length; j++) {
                            StringBuffer sb = new StringBuffer();
                            Date date = new Date(list[j].lastModified());
View Full Code Here

    /**
     * @see org.jnode.fs.FSEntry#setName(String)
     */
    public void setName(String newName) throws IOException {
        SmbFile f = new SmbFile(smbFile.getParent(), newName);
        smbFile.renameTo(f);
    }
View Full Code Here

    public SMBFileSystem(SMBFSDevice device, SMBFileSystemType type) {
        this.type = type;
        this.device = device;
        try {
            root = new SMBFSDirectory(null, new SmbFile("smb://" + device.getUser() + ":" + device.getPassword() + "@"
                + device.getHost() + "/" + device.getPath() + "/"));
            root.smbFile.setDefaultUseCaches(false);
            root.smbFile.connect();
        } catch (IOException e) {
            throw new RuntimeException(e);
View Full Code Here

     */
    public SMBFSEntry addDirectory(final String name) throws IOException {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<SMBFSEntry>() {
                public SMBFSEntry run() throws Exception {
                    SmbFile dir = new SmbFile(smbFile, dirName(name));
                    dir.mkdir();
                    SMBFSDirectory sdir = new SMBFSDirectory(SMBFSDirectory.this, dir);
                    entries.put(name, sdir);
                    return sdir;
                }
            });
View Full Code Here

     */
    public SMBFSEntry addFile(final String name) throws IOException {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<SMBFSEntry>() {
                public SMBFSEntry run() throws Exception {
                    SmbFile file = new SmbFile(smbFile, name);
                    file.createNewFile();
                    SMBFSFile sfile = new SMBFSFile(SMBFSDirectory.this, file);
                    entries.put(name, sfile);
                    return sfile;
                }
            });
View Full Code Here

     * @see org.jnode.fs.FSDirectory#remove(String)
     */
    public void remove(String name) throws IOException {
        SMBFSEntry ent = entries.get(name);
        String fname = ent.isDirectory() ? dirName(name) : name;
        SmbFile file = new SmbFile(smbFile, fname);
        file.delete();
        entries.remove(name);
    }
View Full Code Here

            SWbemServices services = WMI.connect(session, name);


            String path = computer.getNode().getRemoteFS();
            if (path.indexOf(':')==-1)   throw new IOException("Remote file system root path of the slave needs to be absolute: "+path);
            SmbFile remoteRoot = new SmbFile("smb://" + name + "/" + path.replace('\\', '/').replace(':', '$')+"/",createSmbAuth());

            if(!remoteRoot.exists())
                remoteRoot.mkdirs();

            try {// does Java exist?
                logger.println("Checking if Java exists");
                WindowsRemoteProcessLauncher wrpl = new WindowsRemoteProcessLauncher(name,auth);
                Process proc = wrpl.launch("java -fullversion","c:\\");
                proc.getOutputStream().close();
                IOUtils.copy(proc.getInputStream(),logger);
                proc.getInputStream().close();
                int exitCode = proc.waitFor();
                if (exitCode==1) {// we'll get this error code if Java is not found
                    logger.println("No Java found. Downloading JDK");
                    JDKInstaller jdki = new JDKInstaller("jdk-6u16-oth-JPR@CDS-CDS_Developer",true);
                    URL jdk = jdki.locate(listener, Platform.WINDOWS, CPU.i386);

                    listener.getLogger().println("Installing JDK");
                    copyStreamAndClose(jdk.openStream(), new SmbFile(remoteRoot, "jdk.exe").getOutputStream());

                    String javaDir = path + "\\jdk"; // this is where we install Java to

                    WindowsRemoteFileSystem fs = new WindowsRemoteFileSystem(name, createSmbAuth());
                    fs.mkdirs(javaDir);
                   
                    jdki.install(new WindowsRemoteLauncher(listener,wrpl), Platform.WINDOWS,
                            fs, listener, javaDir ,path+"\\jdk.exe");
                }
            } catch (Exception e) {
                e.printStackTrace(listener.error("Failed to prepare Java"));
            }

// this just doesn't work --- trying to obtain the type or check the existence of smb://server/C$/ results in "access denied"   
//            {// check if the administrative share exists
//                String fullpath = remoteRoot.getPath();
//                int idx = fullpath.indexOf("$/");
//                if (idx>=0) {// this must be true but be defensive since all we are trying to do here is a friendlier error check
//                    boolean exists;
//                    try {
//                        // SmbFile.exists() doesn't work on a share
//                        new SmbFile(fullpath.substring(0, idx + 2)).getType();
//                        exists = true;
//                    } catch (SmbException e) {
//                        // on Windows XP that I was using for the test, if the share doesn't exist I get this error
//                        // a thread in jcifs library ML confirms this, too:
//                        // http://old.nabble.com/"The-network-name-cannot-be-found"-after-30-seconds-td18859163.html
//                        if (e.getNtStatus()== NtStatus.NT_STATUS_BAD_NETWORK_NAME)
//                            exists = false;
//                        else
//                            throw e;
//                    }
//                    if (!exists) {
//                        logger.println(name +" appears to be missing the administrative share "+fullpath.substring(idx-1,idx+1)/*C$*/);
//                        return;
//                    }
//                }
//            }

            String id = WindowsSlaveInstaller.generateServiceId(path);
            Win32Service slaveService = services.getService(id);
            if(slaveService==null) {
                logger.println(Messages.ManagedWindowsServiceLauncher_InstallingSlaveService());
                if(!DotNet.isInstalled(2,0, name, auth)) {
                    // abort the launch
                    logger.println(Messages.ManagedWindowsServiceLauncher_DotNetRequired());
                    return;
                }

                // copy exe
                logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveExe());
                copyStreamAndClose(getClass().getResource("/windows-service/jenkins.exe").openStream(), new SmbFile(remoteRoot,"jenkins-slave.exe").getOutputStream());

                copySlaveJar(logger, remoteRoot);

                // copy jenkins-slave.xml
                String xml = createAndCopyJenkinsSlaveXml(id, logger, remoteRoot);

                // install it as a service
                logger.println(Messages.ManagedWindowsServiceLauncher_RegisteringService());
                Document dom = new SAXReader().read(new StringReader(xml));
                Win32Service svc = services.Get("Win32_Service").cast(Win32Service.class);
                int r;
                AccountInfo logOn = getLogOn();
                if (logOn == null) {
                    r = svc.Create(
                        id,
                        dom.selectSingleNode("/service/name").getText()+" at "+path,
                        path+"\\jenkins-slave.exe",
                        Win32OwnProcess, 0, "Manual", true);
                } else {
                    r = svc.Create(
                        id,
                        dom.selectSingleNode("/service/name").getText()+" at "+path,
                        path+"\\jenkins-slave.exe",
                        Win32OwnProcess,
                        0,
                        "Manual",
                        false, // When using a different user, it isn't possible to interact
                        logOn.userName,
                        Secret.toString(logOn.password),
                        null, null, null);

                }
                if(r!=0) {
                    listener.error("Failed to create a service: "+svc.getErrorMessage(r));
                    return;
                }
                slaveService = services.getService(id);
            } else {
                createAndCopyJenkinsSlaveXml(id, logger, remoteRoot);
                copySlaveJar(logger, remoteRoot);
            }

            logger.println(Messages.ManagedWindowsServiceLauncher_StartingService());
            slaveService.start();

            // wait until we see the port.txt, but don't do so forever
            logger.println(Messages.ManagedWindowsServiceLauncher_WaitingForService());
            SmbFile portFile = new SmbFile(remoteRoot, "port.txt");
            for( int i=0; !portFile.exists(); i++ ) {
                if(i>=30) {
                    listener.error(Messages.ManagedWindowsServiceLauncher_ServiceDidntRespond());
                    return;
                }
                Thread.sleep(1000);
View Full Code Here

TOP

Related Classes of jcifs.smb.SmbFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.