Currently I'm doing the functionality for sftp using jsch-0.1.44. I need to add option for the user to browse the directory. So how to get the list of files from the remote server. Is there any other open source exists for this functionality ? Please help me
The ChannelSftp class provides the necessary methods to browse a remote directory.
For listing the directory, use channel.ls("."). This returns a vector of LsEntry objects, which you can traverse, print, show in a window, etc.
This example from jsch examples list shows one way to do this.
Look at the code starting from the following line...
if(cmd.equals("ls") || cmd.equals("dir")){
You can use Apache Virtual File System. If you are creating GUI application you can use OtrosVfsBrowser or VFSJFileChooser.
Related
How can I create a directory in the system where my application is running, At present directory created and files are generated at the server, I need it in client system.
Write a client software, make user install it, let it create anything you want.
directory objects can be created on the server only.
You need to share that directory to the client, using Samba, or whatever networking mechanism applies.
http://docs.oracle.com/cd/E37670_01/E41138/html/ol_about_samba.html
If the client code is a Java application, as an example a
Swing Application
Java FX Application
you can simply use the mkdir method of class File
new File("/mydir").mkdir();
Check if you have the rights to do that.
Am using Apache MINA SSHD to build my own custom SFTP Server.
I want to limit the file system my user sees. I just want them to see the directory structure under /aa/bb/cc
I do not want them to be able to see or navigate any other folder.
And from the directories under /aa/bb/cc, a user will have read access to some directories and write access to only a selected few. How do I achive this ?
The FileSystemView has been introduced for that very purpose. If you're using version 0.14.0, the following will work:
sshServer.setFileSystemFactory(new VirtualFileSystemFactory(new File("admin").getAbsolutePath()));
I have also almost got a working example here. I just have to figure out how to set the home directory dynamically.
I was able to implement moving files from one directory to other in the same system using JAVA URL Connection.But I have to move files from a directory of one server to another(linux or windows) , and I should not use the third party Java APIs. Is there a way how to implement this? If yes , what configuration details are required in the program.please let me know how to implement it.
What about writing a very small script like below..
SOURCEDIR=/home/subodhr/e_books/
DESTDIR=user#server:home/subodhr/Destination/
rsync -avh --exclude="*.bak" $SOURCEDIR $DESTDIR
save this file using .sh extension
like moveFile.sh
then execute the script as ./moveFile.sh
Read the contents into serializable objects and pass them across different machines. Once received, just write them to the disk. You should be able to do this using core Java API.
I have written a java code to copy all directories and files from one location to another location in the same machine and is working well. But, I am not sure how to copy all directories and files from one server to another server. Can someone help
What have you tried so far?
How does your current logic look like?
Consider accessing a directory through the File Object by passing a directory, for example C:\Source. You could also create a File object with \\server\Source when the Source is located on server and is a network share.
Have a look at the documentation of the File object linked above to get further information. Don't forget to test whether the directory is available or not.
I guess your Windows Servers have Samba shares. So your target will look something like this
\192.168.100.111\share\target_dir
First make sure that you have the proper read/write rights on the shared folder. Then map the shared folder to a driveletter. You could take a look at this tutorial: http://compnetworking.about.com/od/windowsxpnetworking/ht/mapnetworkdrive.htm
The way you do it for other versions than XP is mostly the same.
Now you have a driveletter for your target share. So your target looks something like
x:\target_dir
This target can now be used within a java File object.
In addition you could use other libraries to access the samba share directly or use other shares, for example ftp.
I am new to java and trying to learn. Right now I am trying to write a download/upload manager program. I want to make a browse button for FTP so user can select from there which file to download. I can download it writing its directory, manually. Is there a way to do this using JFileChooser or with a similar class? I don't want to use a plugin since I want to write it myself. Thank you for your help.
Not sure what you mean by "I don't want to use a plugin since I want to write it myself". Unless you want to write the complete FTP Client yourself, consider using ftp4j.
JFileChooser is to choose local file(s). Or provide your own FileSystemView with ftp4j backend and use it to choose files on the remote server for download.
Short answer: Just use ftp4j to browse files over FTP.