participate


New To Java - Read and Write from Remote Shared directory
<<   Back to Forum  |   Give us Feedback
5 Duke Stars rewarded for this thread
This topic has 3 replies on 1 page.
buckley
Posts:5
Registered: 8/7/06
Read and Write from Remote Shared directory   
Aug 7, 2006 3:27 AM

 
Hello everyone,

I'm working on an enterprise portal. One of the things i was asked to do is access a remote directory (like "\\machine\share\") and be able to, at least, list the files, download to the portal user any of them, and be able to upload some as well. Also my goal is to create dinamycally a directory inside the shared one for every record I insert into a database for, for example, creating a course (each course has an attachment of files with the schedules, curriculum, etc. in pdf or doc files).

Can anyone point me in the right direction on how to star this? are there any API's, packages or something like that that i can use?

Thank you in advance.
 
LakshmiPeshin
Posts:8
Registered: 3/17/06
Re: Read and Write from Remote Shared directory      
Aug 7, 2006 6:46 AM (reply 1 of 3)  (In reply to original post )

 
Hi,

As long as the machine is in the LAN, you should be able to use java.io.File to carry out any of the operations required.

For example, you should be able to do something like this
import java.io.File;
 
public class RemoteFile
{
       private File myFile;
	
	public RemoteFile()
	{
		myFile = new File("\\\\deepcore\\CMS");
		File[] files = myFile.listFiles();
		for (int i = 0; i < files.length; i++)
		{
			System.out.println(files[i].getName());
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{	
		new RemoteFile();
	}
}


Similarly you should be able to read/write files from/to the share in the remote location.

Hope this helps.

Thanks,
-Lakshmi-
 
JBN
Posts:16
Registered: 8/8/06
Re: Read and Write from Remote Shared directory   
Aug 8, 2006 4:12 AM (reply 2 of 3)  (In reply to original post )

 
I have allready done that type of Project
I use FTP to Connect remote server. there is api call
com.enterprisedt.net.ftp you can download it free
also you can get the document of that API.

there is som sample code

import com.enterprisedt.net.ftp.;


class remote
{

private String localPath,remotePath;
private FTPClient ftpClient;

public remote()
{
try
{
localPath="localpath to download";
remotePath="remote path from server";

ftpClient = new FTPClient();
FTPMessageCollector listener = new FTPMessageCollector();
ftpClient.setMessageListener(listener);
ftpClient.setRemoteHost(ip of the remote host);
ftpClient.setTimeout(10
60 * 1000);
System.out.println("connecting to the Remote Server....");
ftpClient.connect();
System.out.println("connected to the Remote Server ");
ftpClient.login(username,password);
ftpClient.setConnectMode(FTPConnectMode.PASV);
ftpClient.setType(FTPTransferType.ASCII);

downloadFiles();
}

catch(FTPException ftpe)
{
System.out.println(ftpe.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
}


public void downloadFiles()
{
try
{
String [] remoteFileList;
String localFileName;

remoteFileList=ftpClient.dir(remotePath "/");//get the Remote
//file list

for(int j=0;j<remoteFileList.length;j+
)
{
( localFileName =localfile //filter only fileneme from remotFileList[J])
ftpClient.get(localPath localFileName, remoteFileList[j]);
System.out.println("Successfuly Downloaded "

}
ftpClient.quit();
}
}

catch(Exception e)
{
System.out.println(e.toString());
}
}

}

from Jinath

Message was edited by:
JBN
 
buckley
Posts:5
Registered: 8/7/06
Re: Read and Write from Remote Shared directory   
Aug 9, 2006 8:34 AM (reply 3 of 3)  (In reply to #2 )

 
Thank you very much for your help. I tried to access the shared directory locally and had no problem at all.
But a problem persists. When i deply my code to the portal server, it doen't access the directory because it doen't have the same access rights i have. So, my question is: is there a way to, at the same time i access the shared folder with the File class to send also the user-pass required for it to have access ?

Thank you again
 
This topic has 3 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums