标签: apache-commons-vfs

如何检查FileObject是否是文件夹?

我正在使用Apache Commons VFS(虚拟文件系统)通过SFTP访问某些文件.有谁知道如何检查org.apache.commons.vfs.FileContent的实例是否是文件夹?

java apache-commons-vfs

4
推荐指数
1
解决办法
2521
查看次数

Apache VFS2-无法将文件上传到SFTP服务器

我正在尝试使用Apache VFS2将文件上传到SFTP服务器。使用WinSCP等客户端时,SFTP正常运行。我举了一些互联网上使用Java客户端的示例,但是我一直在出错。使用的版本是2.3。代码:

public class SftpPersister
{
    private static final Logger logger          = Logger.getLogger( SftpPersister.class );

    String                      serverAddress   = "ftp.domain.com";
    String                      user            = "myuser";
    String                      password        = "mypass";
    String                      remoteDirectory = "outgoing/";
    String                      localDirectory  = "c:/users/user/";

   public static void main( String[] args )
   {
      new SftpPersister().upload( "ntuser.ini" );
   }

   public boolean upload( String fileName )
   {
      StandardFileSystemManager manager = new StandardFileSystemManager();

      try
      {

        //check if the file exists
        String filepath = localDirectory + fileName;
        File file = new File( filepath ); …
Run Code Online (Sandbox Code Playgroud)

java sftp apache-commons-vfs

4
推荐指数
2
解决办法
604
查看次数

Apache Commons VFS:使用 FTP

我正在尝试通过 FTP 使用 Apache Commons VFS。在我的 FTP 上有下一个文件和文件夹结构:

/
/test
/test/in
/test/in/file1.txt
/test/in/file2.txt
Run Code Online (Sandbox Code Playgroud)

我需要连接并读取文件夹 /test/in 中的所有文件(它一直在变化)。代码:

        FileSystemManager fsManager = null;
        FileSystem fs = null;
        FileSystemOptions opts = new FileSystemOptions();
        fsManager = VFS.getManager();

        FileObject path = fsManager.resolveFile("ftp://user:password@my.ftp.host/test/in/", opts);

        fs = path.getFileSystem();

        //prints Connection successfully established to /test/in
        System.out.println("Connection successfully established to " + path.getName().getPath());
Run Code Online (Sandbox Code Playgroud)

但是我无法获得文件列表,因为它说 /test/in 不存在。A 做了一些测试来检查文件类型:System.out.println(path.getType());使用不同的路径。结果:

ftp://user:password@my.ftp.host/test - 文件

ftp://user:password@my.ftp.host/test/in - 虚构

ftp://user:password@my.ftp.host/test/in/file1.txt - 文件

FileType.IMAGINARY 表示该文件不存在。任何想法如何使用 ftp 文件夹?

java ftp apache-commons-vfs

3
推荐指数
1
解决办法
1万
查看次数

vfs2和samba(smb)版本2

我们在Windows机器上禁用了smbv1,现在我们无法使用smb2连接我们使用commons-vfs2(2.0)和commons-vfs2-sandbox(2.0)这里是我的代码:

@Test
    public void testConnection() throws FileSystemException {
         String folder = "\\\\10.0.0.0\\smb";

        folder = folder.replaceAll("\\\\", "/");
        StringBuilder builder = new StringBuilder(128).append(Protocol.CIFS.getProtocolPrefix()).append(':')
                .append(folder);
        String fileURI = builder.toString();
        System.out.println(fileURI);

        FileSystemOptions fsOptions = null;

        String password = "mAdmin";
        String username = "myPassword";
        String domain = "";
        StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password);
        fsOptions = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fsOptions, auth);
        FileSystemManager manager = VFS.getManager();

        FileSystemManager fileSystemManager = manager;
        FileObject fileObject = fileSystemManager.resolveFile(fileURI, fsOptions);
        boolean result = fileObject.isReadable();

        System.out.println(fileURI +" " + result);
    }
Run Code Online (Sandbox Code Playgroud)

这就是我禁用smb …

java smb vfs apache-commons-vfs

1
推荐指数
1
解决办法
1328
查看次数

标签 统计

apache-commons-vfs ×4

java ×4

ftp ×1

sftp ×1

smb ×1

vfs ×1