Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.8k views
in Java FTP by (160 points)
I am using mac os x to realize an simple example for transeferring file but at run time I have
the error : com.enterprisedt.net.ftp.FTPException: 500 Illegal PORT command.
I use the following code:
import java.awt.FileDialog;
import java.io.IOException;

import javax.swing.JOptionPane;

import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FileTransferClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.*;


public class FileFTPUpload {

public String mostraDialogo(String nuovoNome)
{
String title = "File Chooser";
FileDialog dialog = new FileDialog(JOptionPane.getRootFrame(),title);
dialog.setVisible(true);


FileTransferClient ftp = new FileTransferClient();

try{
ftp.getAdvancedSettings().setControlEncoding("Windows-1252");


Logger.addAppender(new FileAppender("myLogFileName.txt"));

Logger.setLevel(Level.DEBUG);

ftp.setRemoteHost("....");

ftp.setUserName(".....");

ftp.setPassword("....");

//ftp.setRemotePort(21);
//ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
//ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.ACTIVE);

//ftp.getAdvancedFTPSettings().setActivePortRange(61500, 61510);

}catch(Exception ex){ex.printStackTrace();}

if (dialog.getFile() != null) {
//System.out.println(dialog.getDirectory() + dialog.getFile());

String localFilePath = dialog.getDirectory() + dialog.getFile();


try {
ftp.connect();
ftp.uploadFile(localFilePath, "testupload\\"+nuovoNome);


} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
ftp.disconnect();

//System.exit(0);
} catch (FTPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dialog.getDirectory() +dialog.getFile() + "/" + nuovoNome;
} else {
//System.out.println("0");*/
//System.exit(0);
return "0";
}
}
This code on a windows machine don't produce errors.
The output of the logger is:

DEBUG [FileTransferClient] 14 gen 2011 15:52:13.102 : Configured client
DEBUG [FTPClient] 14 gen 2011 15:52:13.144 : Connecting to ..../......
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.210 : 220 (vsFTPd 2.0.5)
DEBUG [FileTransferClient] 14 gen 2011 15:52:13.215 : Client connected
DEBUG [FileTransferClient] 14 gen 2011 15:52:13.216 : Logging in
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.219 : ---> USER .....
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.222 : 331 Please specify the password.
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.223 : ---> PASS ********
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.234 : 230 Login successful.
DEBUG [FileTransferClient] 14 gen 2011 15:52:13.236 : Logged in
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.236 : ---> TYPE I
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.238 : 200 Switching to Binary mode.
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.242 : ---> PWD
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.244 : 257 "/"
DEBUG [FTPClient] 14 gen 2011 15:52:13.343 : Attempt #1
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.350 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.384 : ---> PORT 0,0,0,0,222,102
DEBUG [FTPControlSocket] 14 gen 2011 15:52:13.385 : 500 Illegal PORT command.
INFO [FTPControlSocket] 14 gen 2011 15:52:13.386 : Expected reply codes = [200,250]

What I don't understand is the PORT output PORT 0,0,0,0,222,102 : on the windows machine the four zeros are the four places of the ip address.
Every help isreally usefull for me because are days that I am not able to solve this problem.
Thank in advance.

2 Answers

0 votes
by (162k points)
You might need to specify the active IP address - the IP address that the server connects back to. This might be the IP address of the client machine. There's a method to do this.
0 votes
by (160 points)
Thank : now also on the mac os x machine go right.
I have lost 3 days on this problem but at the end I have solved
using your suggestion.

Thank a lot again

Categories

...