How to get current working directory of the ftp server,in java application

Hi All,

I抦 FTP?** the file using java.net.url.

Here is the snippet of the code:

public void ftpFile()throws ChrsException

{

try

{

System.out.println("FTPing the file '"+localfile+"'");

OutputStream os = openUploadStream(targetfile);

FileInputStream is = new FileInputStream(localfile);

byte[] buf = new byte[16384];

int noOfBytesRead;

while (true)

{

//Read the data from the source File into buf

noOfBytesRead = is.read(buf);

if (noOfBytesRead <= 0)

break;

//Writes the data present in the buf to the target file

os.write(buf, 0, noOfBytesRead);

}

os.close();

is.close();

close();

System.out.println ("The file '"+localfile+"' is Sucessfully FTP'd to '"+targetfile+"'");

}

catch (MalformedURLException malExcp)

{

System.out.println ("Invalid URL. Error in FTP'*** the file: \""+localfile+"\"");

}

catch(IOException ioe)

{

System.out.println ("Error in FTP'*** the file: \""+localfile+"\"");

}

}

private OutputStream openUploadStream(String targetfile) throws MalformedURLException, IOException

{

URL url = null;

//Creates a URL object with FTP protocol

if (user == null)

{

url = new URL("ftp://" + host + "/" + targetfile + ";type=i");

}

else

{

url = new URL("ftp://" + user + ":" + password + "@" + host + "/" + targetfile + ";type=i");

}

urlc = url.openConnection();

//Get the OutputStream that writes to this connection.

OutputStream os = urlc.getOutputStream();

return os;

}

Now I need to find what the current directory is when the user logs in with username and password on to the FTP server in java.

Thanks in Advance.

[1864 byte] By [3A-_@.a] at [2007-11-27 8:51:31]
# 1
Why do you need that? Surely all you're interested in is where it's going
georgemca at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 2
once i login to the machine using ftp, i need to know the current working directory
3A-_@.a at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 3
The current directory is '.'. That's all you can know. All you can do is cd to an existing directory below that, or create one below that. You can't do anything else. So you don't need to know.
ejpa at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 4
> once i login to the machine using ftp, i need to know> the current working directoryNo you don't. The ftp server presents you with it's own view of the filesystem, that's all you need to know
georgemca at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 5
> once i login to the machine using ftp, i need to know> the current working directoryNo, you don't. And in general, ftp will deliberately hide that information from you.
jverda at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 6
as soon as user logs in he is taken to the directory "ftproot/pub/abc". now If I execute pwd command , is hould be able to get to know tht user is under "ftproot/pub/abc"So I need to exceute "pwd" command once i log in.Dont know how to do that.
3A-_@.a at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 7

> as soon as user logs in he is taken to the directory

> "ftproot/pub/abc".

That's the server's business. The client has no reason or right to know that.

> now If I execute pwd command , is hould be able to

> get to know tht user is under "ftproot/pub/abc"

No, you shouldn't. From the client's perspective, that's / and that's all the client needs to know.

jverda at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 8

> as soon as user logs in he is taken to the directory

> "ftproot/pub/abc".

> now If I execute pwd command , is hould be able to

> get to know tht user is under "ftproot/pub/abc"

Three respected posters, well two plus me ;-), have just told you otherwise. The information about the current directory is (a) secure and (b) useless to the user, as he can't do anything with it. The user doesn't want to know that at all and you shouldn't try to tell him. And in any case FTP doesn't support it, again for security reasons, so you can't do it.

Just accept it.

ejpa at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...
# 9

> as soon as user logs in he is taken to the directory

> "ftproot/pub/abc".

> now If I execute pwd command , is hould be able to

> get to know tht user is under "ftproot/pub/abc"

The whole point of the server putting you in that directory is that they don't want ftp clients to see any part of the file system other than that piece.

jverda at 2007-7-12 21:04:53 > top of Java-index,Java Essentials,New To Java...