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.

