• Post Reply Bookmark Topic Watch Topic
  • New Topic

using FTP view client machine files  RSS feed

 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to connect any machine(os independant) using FTP program view the cient machine files.
but i wrote the file like

using login window i have to give username,password,and host

after servlet
import java.io.*;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sun.net.ftp.FtpClient;
import sun.net.TelnetInputStream;

public class Controller extends HttpServlet
{
public Controller() {}

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
doPost(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{

FtpClient ftpClient = new FtpClient();
FtpClient fc;
Controller getFileList =new Controller();

try
{
String host = req.getParameter("iptxt");
String username = req.getParameter("username");
String password = req.getParameter("pwd");
String path = "/";

FtpClient client = new FtpClient(host);
client.login(username, password);
client.binary();

RequestDispatcher disp = getServletContext().getRequestDispatcher("/Browser.jsp");
req.setAttribute("host",host);
req.setAttribute("username",username);
req.setAttribute("password",password);
disp.forward(req, resp);
}
//client.cd(directory);

//InputStream is = client.get(fname);

/*if(path.indexOf(".") > 0)
{
String filename = path;
InputStream is = client.get(filename);
BufferedInputStream bis = new BufferedInputStream(is);

OutputStream os = new FileOutputStream(filename);
BufferedOutputStream bos = new BufferedOutputStream(os);

byte[] buffer = new byte[1024];
int readCount;

System.out.println("Getting: " + filename);

while( (readCount = bis.read(buffer)) > 0)
{
bos.write(buffer, 0, readCount);
}
bos.close();
return;
}
else
{
String directory = path;
client.cd(directory);
getFileList.directoryList(client,directory);
}
//client.closeServer();
}
catch (Exception e)
{
System.out.println("Exception occured" + e);
}


}


public void directoryList(FtpClient client,String directory) {
try
{
TelnetInputStream telnet = client.list();
int i = telnet.read();

String s = new String();
ArrayList arr = new ArrayList();
while (i > 0)
{
i = telnet.read();
if(i == 10)
{
arr.add(s);
s = "";
}
else
{
s = s + (char)i;
}
}
String[] sArr = null;
for (int j=1; j<arr.size(); j++)
{
sArr = arr.get(j).toString().split(" ");
if(sArr[0].charAt(0) != 'd')
System.out.println("File Name -->" + sArr[sArr.length-1]);
else if ((sArr[sArr.length-1]).equals(".")){}
else if ((sArr[sArr.length-1]).equals("..")){ }
else {
System.out.println("Directory -->" + sArr[sArr.length-1]);
client.cd(sArr[sArr.length-1]);
directory = sArr[sArr.length-1];
directoryList(client,directory);
}

} // for
} // try

catch (Exception e)
{
System.out.println("Exception occured" + e);
} //catch
} //method
}


after i will get o/p like this format

http://www.mycgiserver.com/~tobin/Browser.jsp?sort=1&file=%2Fusr%2Flocal%2Fresin%2Fdoc%2F~tobin%2FBrowser.jsp

but this program runs where is server is availble that machine files only shown.

but where i would connect using ftp,i would like to display this format


any one give idea

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not JSP related, so moved to the Servlets forum.
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehrm and what is the original question?

Please explain your question in more detail.

J.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like another "I want to spy on my users and look at what they have on their harddisks when they access my website" type of question.
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both guys(Jeroen Wenting,Jeffrey Spaulding) thanks for reply....
But my question is not like ur thought.

I will give valid hostname(ipaddress,Username,password)
i will get that ipaddress,username,password what r the files are aviable.

First files is connect the system using FTP(FTP login)
Second url is display the files and directoried(avilable ownership rights permission files and directories) etc

it is not meaning of hacking,if access internet system,access the local files and directoy.


in our application we have use like that.

once more read it and any one help me.

Thanks
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
it would be product like smartftp.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the client machine doesn't have an FTP server running, you're not going to be able to browse it's files from a servlet.
[ March 11, 2005: Message edited by: Ben Souther ]
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
client is available services for FTP service.
which are all(Client machine)machines are going to connect and browse the files.Before That i will do enable the FTPservice for Client machine.

I am going to develop like smartFTP tool.

i have to program first is servlet( connect the cilent machine using FTP) II nd one is url (browse the files).

how to merge the two files

or give me own solution any one

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!