• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make directories

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a new directory on a remote FTP Server using an extended version of sun.net.ftp.FtpClient.class but i can't seem to get the commands right. My class is as follows :
public class FClient extends FtpClient {
public FClient(String host) throws IOException{
super(host);
}
public void mkDir(String dir) {
try {
issueCommand("mkdir "+dir);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
as you can see it's very basic because i only need one function.
Can anyone tell me what is wrong with my code?
Or if i have a problem with my ftp command?
Pete
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dunno abt sun's FTP client, I am writing my own these days, isn't it "MKD <SP> <pathname> <CRLF>"
as per RFC 959? what's the exception you are getting?
Here are standard responses for MKD command, as per RFC 959 -
257 => success
500, 501, 502, 421, 530, 550 => errors
521 = > error - directory already exists, taking no action
Search for more datils at the rfc site -
ftp://ftp.isi.edu/in-notes/rfc959.txt
HTH,
- Manish
BTW, where's this sun's FTP client? where can I find it?
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the exception that i'm getting :
java.io.FileNotFoundException: MKD ./peterTest/509/VV00A00A/: 550 ./peterTest/50
9/VV00A00A/: File exists.
Can you tell me what i can do about it?
sun.net.ftp.FtpClient is available in 'rt.jar' which is a part of JDK 1.2.
Pete
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manish,
in "MKD <SP> <pathname> <CRLF>"
what's <SP> and <CRLF>?
Pete
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<SP> is space and <CRLF> is carriage return and line feed, i.e "\r\n" without quotes. That's standard FTP sequence.
The exception seems to say that "file already exists", i.e. the directory you are trying to create already exists, the response code from the server (apparently 550) says -
550 Requested action not taken.
File unavailable (e.g., file not found, no access).
There could be various reasons for this code, such as - directry already exists on the server, you may not have permission to create directory on the server etc. You'll need to find the exact reasons from your FTP server response.
If directory already exists on the server, you can delete it, again if the dir is not empty, it will send error code, and you will need to delete all the files from the directory before you can delete it. But perhaps, if directory already exists, you might not want to delete it in the first place.
If sun has documented this package, maybe you can find more info on it in the docs. (I couldn't find any documentaion abt it in my JDK 1.2 doc)
HTH,
- Manish
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manish,
Can you give me an example of how to write the pathname including all the dots and slashes? I'm still having trouble getting my program to make a directory on the server. I've tried lots of different variations on the pathname but i can't get it right.
Pete
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK!
Let me try, don't know if it's valid in your case.
Say if my host is ftp.somehost.com and MY root directory on the host is /users/manish. So when I log in I would be at -
ftp.somehost.com/users/manish/ which is my root as well as home on the remote server.
If I want to create a directory named "Java" under my root directory I will simply send command to the FTP sever as -
MKD <space> Java<CRLF>
and if the server sends response 257 it means the directory has been created, any other response would mean error.
The same command can also be issued as -
MKD <space> /users/manish/Java<CRLF>
Now to allow this specific form or not is entirely upto your FTP server, it may or may not allow it to be created, depending upon its configuration (AFAIK).
If you have create dir rights under your root directory, the first command should always be successful.
Now consider a case when you are under dir -
ftp.somehost.com/users/manish/Java
and you want to create a new directory called CPP under "your root" (i.e. - ftp.somehost.com/users/manish/) you should send command such as -
MKD <space> ../CPP<CRLF>
This will create a directory such as -
ftp.somehost.com/users/manish/CPP, but your present dir is still ftp.somehost.com/users/manish/Java .
You can download a free FTP server such as
Cerberus FTP Server (windows) so that you can test your code locally by configuring the FTP server the way you want. That way you can be sure that your application code is working correctly and it's a problem with the remote FTP server.
Do let me kow if this helps,
Regards,
- Manish
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank's for all your help so far. I've tried a few of the ftp clients available on the net but i keep getting the same problems. It's possible that the problem is with the server and mot my client.
Watch this space, i'll post an update soon!!
Pete
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried make a directory on the server again but now it's returning an error to my
application after i run this line of code :
client.makeDirectory("peterTest/509");
Returns :-
553 Could not determine cwdir: No such file or directory.
Any idea of what would cause this reply from the server?
Pete
(dir peterTest exists, dir 509 dosen't)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic