• Post Reply Bookmark Topic Watch Topic
  • New Topic

FTP Problem  RSS feed

 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm stuck on this piece of code and was wondering if anyone could help?
Here's my method. The problem is with the method binary() (see below)

The error i'm getting is:
500 '': command not understood.
I don't understand why this is happening because the first call to binary() works fine.
Please can anyone help?
Pete
P.S.
The class i'm using is sun.net.ftp.FtpClient
---I add the UBB code tag to try and make this easier to read.--Carl
[ February 18, 2002: Message edited by: Carl Trusiak ]
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exception are you getting? you should printout the Stack Trace for exceptions f, g and h. Don't assume that they are some set exception. This could be a user permission problem on the ftp server.
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exceptions arn't the problem. The code checks for existing directories using the exceptions. I'll explain the problem properly :
There are three possibilities when i connect to the Ftp server
1.Don't need to create directories, only write.
2.Need to create 1 directory
3.Create 2 directories.
these are the exceptions being caught. If i don't need to create any directories client.binary() works. when i need to create directories then the binary method doesn't work. The server response to the method is :
500 '': command not understood.
and i don't know why this is happening.
Have you got any suggestions?
Pete
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot about this,
sun.net.ftp.FtpProtocolException: TYPE I
at sun.net.ftp.FtpClient.issueCommandCheck(FtpClient.java:168)
at sun.net.ftp.FtpClient.binary(FtpClient.java:368)
at archivetool.FTPClientDialog.connect(FTPClientDialog.java:371)
This is the Exception caused by the Ftp server returning 500 '': command not understood.
Pete
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think you are missing some important messages. I notice you don't read the response of the server on connection. Are you positive you connected?
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the full method which i'm using to connect to the server with including all lines added for testing.
boolean connect() {
fileStruct();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
taDisplay.setText("");
String user = tfUserName.getText();
String vn = "161.63.195.3";
taDisplay.appendText("Connecting to host "+vn);
client = new FClient(vn);
client.login(user, pw);
taDisplay.appendText("\nUser "+user+" login OK");
try {
client.cd(dir);
System.out.println("cd1");
//client.binary();
String b = client.getResponseString();
System.out.println("binary returns = "+b);
System.out.println("cd2");
}
catch (IOException f) {
String a = client.getResponseString();
System.out.println("string a = "+a);
System.out.println("exception f");
try {
client.cd("peterTest/"+pdp);
String c = client.getResponseString();
System.out.println("String c = "+c);
client.mkDir(partNumber);
String d = client.getResponseString();
System.out.println("String d = "+d);
//client.cd("/usr7/sa/peterTest/"+pdp+"/"+partNumber);
System.out.println("PartNumber = "+partNumber);
client.cd(partNumber);
String e = client.getResponseString();
System.out.println("String e = "+e);
//client.binary();
String l = client.getResponseString();
System.out.println("String l = "+l);
}
catch (IOException g) {
String m = client.getResponseString();
System.out.println("string m = "+m);
System.out.println("exception g");
try {
client.mkDir("peterTest/"+pdp);
client.mkDir("peterTest/"+pdp+"/"+partNumber);
client.cd(dir);
String i = client.getResponseString();
System.out.println("client.cd returns = "+i);
//client.binary();//this line not working
}
catch (IOException h) {
String j = client.getResponseString();
System.out.println("Binary error = "+j);
System.out.println("exception h");
h.printStackTrace();
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return false;
}
}
}
client.binary();
}
catch (IOException e) {
System.out.println("exception e");
e.printStackTrace();
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
return false;
}
return true;
}
==================================================
Here's the full stack trace and test messages when the directories don't exist:
string a = 550 peterTest/508/BB99F55T: No such file or directory.
exception f
string m = 550 peterTest/508: No such file or directory.
exception g
client.cd returns = 257 MKD command successful.
exception e
sun.net.ftp.FtpProtocolException: TYPE I
at sun.net.ftp.FtpClient.issueCommandCheck(FtpClient.java:168)
at sun.net.ftp.FtpClient.binary(FtpClient.java:368)
at archivetool.FTPClientDialog.connect(FTPClientDialog.java:386)
at archivetool.FTPClientDialog.bClose_actionPerformed(FTPClientDialog.java:178)
at archivetool.FTPClientDialog$2.actionPerformed(FTPClientDialog.java:86)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3715)
at java.awt.Component.processEvent(Component.java:3544)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:926)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.Dialog.show(Dialog.java:380)
at archivetool.ArchiveMain.bArchive_actionPerformed(ArchiveMain.java:385)
at archivetool.ArchiveMain$14.actionPerformed(ArchiveMain.java:281)
at java.awt.Button.processActionEvent(Button.java:329)
at java.awt.Button.processEvent(Button.java:302)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
The test messages tell me that i'm connected to the server and have created the right directories. The exception is thrown when client.binary() is called at the end of the method. As you can see i have moved the call to the binary method but the exception is the same as before. I've tried rearranging the code but nothing is helping.
Pete
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the code for FClient binary()?
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an extension of sun.net.ftp.FtpClient there's not much documentation on it but see the site below :
http://swig.stanford.edu/pub/java/javadoc/sun/net/ftp/FtpClient.html
it has a class description.
FClient.class :
public class FClient extends FtpClient {
int r;
public FClient(String host) throws IOException {
super(host);
}
public void mkDir(String dir) {
try {
issueCommand("MKD "+dir+"\r\n");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
I've only extended one method because in FtpClient issueCommand() is a protected method.

Pete
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you've read all the cautions surrounding the sun packages. I think this is slightly flawed, it issues the Type I command to the ftp server. Not all servers implement this in that manner. Override the binary and ascii methods in your FClient

Give that a try.
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i tried to compile binaryMode=false like you suggested, i got this error :
archivetool/FClient.java:24: binaryMode has private access in sun.net.ftp.FtpClient
binaryMode = true;
so i commented the lines out and got the Exception below instead, it's same thing as before.
sun.net.ftp.FtpProtocolException: BINARY
at sun.net.ftp.FtpClient.issueCommandCheck(FtpClient.java:168)
at archivetool.FClient.binary(FClient.java:22)
at archivetool.FTPClientDialog.connect(FTPClientDialog.java:388)
at archivetool.FTPClientDialog.bClose_actionPerformed(FTPClientDialog.java:178)
at archivetool.FTPClientDialog$2.actionPerformed(FTPClientDialog.java:86)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3715)
at java.awt.Component.processEvent(Component.java:3544)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:926)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.Dialog.show(Dialog.java:380)
at archivetool.ArchiveMain.bArchive_actionPerformed(ArchiveMain.java:385)
at archivetool.ArchiveMain$14.actionPerformed(ArchiveMain.java:281)
at java.awt.Button.processActionEvent(Button.java:329)
at java.awt.Button.processEvent(Button.java:302)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
The FtpCLient.binary() method is working when the mkDir() method is not called, but won't work when i make a directory first.

Pete
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I still can't get past the fact that I don't believe the error message you are getting is the root of the problem. Lets's try this remove the binary() and ascii() methods I had you add. Change the mkdir() method to
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carl,
If you were here right now i'd kiss you.
The code has worked, I've tested it 5 times without a problem.
Thanks for all your help
Pete
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!