ftp - How to list files directory/files using Apache Common vfs -
i new using apache mutual vfs, success connect server read docs i'm stuck in code. how can list directory/files?
.... session session = null; filesystemmanager fsmanager = null; filesystem fs = null; seek { string host = "host_here"; int port = 22; string userstr = "user_here"; char [] username = userstr.tochararray(); string passstr = "password_here"; char [] password = passstr.tochararray(); session = sftpclientfactory.createconnection(host, port, username, password, null); //session.connect(); system.out.println("connected server"); filesystemoptions opts = new filesystemoptions(); fsmanager = vfs.getmanager(); fileobject file = fsmanager.resolvefile("ftp://"+userstr+":"+passstr+"@"+host+"/home/", opts); // .... whats next here? ..... } grab (exception e) { session.disconnect(); e.printstacktrace(); } ...
please help me, give thanks before :)
list of files can displayed using fileobject#getchildren() method.
filesystemoptions opts = new filesystemoptions(); fsmanager = vfs.getmanager(); // list files in directory.try give directory path fileobject localfileobject=fsmanager.resolvefile("ftp://"+userstr+":"+passstr+"@"+host+"/home"); fileobject[] children = localfileobject.getchildren(); ( int = 0; < children.length; i++ ){ system.out.println( children[ ].getname().getbasename() ); } // end of list files. fileobject file = fsmanager.resolvefile("ftp://"+userstr+":"+passstr+"@"+host+"/home/", opts);
my suggestion utilize jsch framework best sftp operations. apache mutual vfs
inherently used framework.the complexcity reduced jsch
.
ftp file-transfer jsch apache-commons-vfs
No comments:
Post a Comment