Examples of SshFile


Examples of org.apache.sshd.common.file.SshFile

    private Reply doProcessRmdir(SshFxpRmdirRequest request) throws IOException {
        int id = request.getId();
        String path = request.getPath();
        // attrs
        SshFile p = resolveFile(path);
        if (p.isDirectory()) {
            if (p.doesExist()) {
                if (p.listSshFiles().size() == 0) {
                    if (p.delete()) {
                        return new SshFxpStatusReply(id, SSH_FX_OK, "");
                    } else {
                        return new SshFxpStatusReply(id, SSH_FX_FAILURE, "Unable to delete directory " + path);
                    }
                } else {
                    return new SshFxpStatusReply(id, SSH_FX_DIR_NOT_EMPTY, path);
                }
            } else {
                return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_PATH, path);
            }
        } else {
            return new SshFxpStatusReply(id, SSH_FX_NOT_A_DIRECTORY, p.getAbsolutePath());
        }
    }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

    private Reply doProcessMkdir(SshFxpMkdirRequest request) throws IOException {
        int id = request.getId();
        String path = request.getPath();
        // attrs
        SshFile p = resolveFile(path);
        if (p.doesExist()) {
            if (p.isDirectory()) {
                return new SshFxpStatusReply(id, SSH_FX_FILE_ALREADY_EXISTS, p.getAbsolutePath());
            } else {
                return new SshFxpStatusReply(id, SSH_FX_NOT_A_DIRECTORY, p.getAbsolutePath());
            }
        } else if (!p.isWritable()) {
            return new SshFxpStatusReply(id, SSH_FX_PERMISSION_DENIED, p.getAbsolutePath());
        } else if (!p.mkdir()) {
            return new SshFxpStatusReply(id, SSH_FX_FAILURE, "Error creating dir " + path);
        } else {
            return new SshFxpStatusReply(id, SSH_FX_OK, "");
        }
    }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

    }

    private Reply doProcessRemove(SshFxpRemoveRequest request) throws IOException {
        int id = request.getId();
        String path = request.getPath();
        SshFile p = resolveFile(path);
        if (!p.doesExist()) {
            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_FILE, p.getAbsolutePath());
        } else if (p.isDirectory()) {
            return new SshFxpStatusReply(id, SSH_FX_FILE_IS_A_DIRECTORY, p.getAbsolutePath());
        } else if (!p.delete()) {
            return new SshFxpStatusReply(id, SSH_FX_FAILURE, "Failed to delete file");
        } else {
            return new SshFxpStatusReply(id, SSH_FX_OK, "");
        }
    }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

    }

    private Reply doProcessOpendir(SshFxpOpendirRequest request) throws IOException {
        int id = request.getId();
        String path = request.getPath();
        SshFile p = resolveFile(path);
        if (!p.doesExist()) {
            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_FILE, path);
        } else if (!p.isDirectory()) {
            return new SshFxpStatusReply(id, SSH_FX_NOT_A_DIRECTORY, path);
        } else if (!p.isReadable()) {
            return new SshFxpStatusReply(id, SSH_FX_PERMISSION_DENIED, path);
        } else {
            Handle handle = createDirectoryHandle(p);
            return new SshFxpHandleReply(id, handle);
        }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

            path = sshFxpLstatRequest.getPath();
        } else {
            SshFxpStatRequest sshFxpStatRequest = (SshFxpStatRequest) sftpRequest;
            path = sshFxpStatRequest.getPath();
        }
        SshFile p = resolveFile(path);
        if (!p.doesExist()) {
            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_FILE, p.getAbsolutePath());
        }
        int flags = SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_SIZE;
        return new SshFxpAttrsReply(id, new FileAttributes(p, flags));
    }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

        if (!(p instanceof FileHandle)) {
            return new SshFxpStatusReply(id, SSH_FX_INVALID_HANDLE, handle);
        } else {
            FileHandle fh = (FileHandle) p;
            fh.write(data, offset);
            SshFile sshFile = fh.getFile();

            sshFile.setLastModified(new Date().getTime());

            return new SshFxpStatusReply(id, SSH_FX_OK, "");
        }
    }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

        int accValue = request.getAcc();
        if (accValue == 0) {
            String path = request.getPath();
            int flags = request.getFlags();
            // attrs
            SshFile file = resolveFile(path);
            if (file.doesExist()) {
                if (((flags & SSH_FXF_CREAT) != 0) && ((flags & SSH_FXF_EXCL) != 0)) {
                    return new SshFxpStatusReply(id, SSH_FX_FILE_ALREADY_EXISTS, path);
                }
            } else {
                if ((flags & SSH_FXF_CREAT) != 0) {
                    if (!file.isWritable()) {
                        return new SshFxpStatusReply(id, SSH_FX_PERMISSION_DENIED, "Can not create " + path);
                    }
                    file.create();
                }
            }
            if ((flags & SSH_FXF_TRUNC) != 0) {
                file.truncate();
            }
            return new SshFxpHandleReply(id, createFileHandle(file, flags));
        } else {
            String path = request.getPath();
            int acc = accValue;
            int flags = request.getFlags();
            // attrs
            SshFile file = resolveFile(path);
            switch (flags & SSH_FXF_ACCESS_DISPOSITION) {
                case SSH_FXF_CREATE_NEW: {
                    if (file.doesExist()) {
                        return new SshFxpStatusReply(id, SSH_FX_FILE_ALREADY_EXISTS, path);
                    } else if (!file.isWritable()) {
                        return new SshFxpStatusReply(id, SSH_FX_PERMISSION_DENIED, "Can not create " + path);
                    }
                    file.create();
                    break;
                }
                case SSH_FXF_CREATE_TRUNCATE: {
                    if (file.doesExist()) {
                        return new SshFxpStatusReply(id, SSH_FX_FILE_ALREADY_EXISTS, path);
                    } else if (!file.isWritable()) {
                        return new SshFxpStatusReply(id, SSH_FX_PERMISSION_DENIED, "Can not create " + path);
                    }
                    file.truncate();
                    break;
                }
                case SSH_FXF_OPEN_EXISTING: {
                    if (!file.doesExist()) {
                        if (!file.getParentFile().doesExist()) {
                            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_PATH, path);
                        } else {
                            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_FILE, path);
                        }
                    }
                    break;
                }
                case SSH_FXF_OPEN_OR_CREATE: {
                    if (!file.doesExist()) {
                        file.create();
                    }
                    break;
                }
                case SSH_FXF_TRUNCATE_EXISTING: {
                    if (!file.doesExist()) {
                        if (!file.getParentFile().doesExist()) {
                            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_PATH, path);
                        } else {
                            return new SshFxpStatusReply(id, SSH_FX_NO_SUCH_FILE, path);
                        }
                    }
                    file.truncate();
                    break;
                }
                default:
                    throw new IllegalArgumentException("Unsupported open mode: " + flags);
            }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

    protected SshFxpNameReply sendName(int id, Iterator<SshFile> files) throws IOException {
        SshFxpNameReply reply = new SshFxpNameReply(id);
        int nb = 0;
        while (files.hasNext() && nb < MAX_PACKET_LENGTH / 2) {
            SshFile f = files.next();
            String filename = f.getName();
            if (version <= 3) {
                nb += 55 + filename.length() * 2;
            } else {
                nb += filename.length();
            }
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

        String homeDir = System.getProperty("user.dir");
        NativeFileSystemFactory vfs = new NativeFileSystemFactory();

        FileSystemView view = vfs.createFileSystemView(new TestSession());

        SshFile file = view.getFile("foo");
        String physicalName = ((NativeSshFile) file).getNativeFile().getAbsolutePath();
        assertEquals(homeDir + File.separator + "foo", physicalName);

        file = view.getFile(view.getFile("foo"), "../bar");
        physicalName = ((NativeSshFile) file).getNativeFile().getAbsolutePath();
View Full Code Here

Examples of org.apache.sshd.common.file.SshFile

        String homeDir = System.getProperty("user.dir");
        VirtualFileSystemFactory vfs = new VirtualFileSystemFactory(homeDir);

        FileSystemView view = vfs.createFileSystemView(new TestSession());

        SshFile file = view.getFile("foo");
        String physicalName = ((NativeSshFile) file).getNativeFile().getAbsolutePath();
        assertEquals(homeDir + File.separator + "foo", physicalName);

        file = view.getFile(view.getFile("foo"), "../bar");
        physicalName = ((NativeSshFile) file).getNativeFile().getAbsolutePath();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.