?
=?ISO-8859-1?Q?Xaver_S=FCnkeler?=
Hello,
I'm trying to write some code to download a file from a ftp server and
I'm not quite sure, if I have understood the FTP-RFC.
Code goes like this:
m_socket = new Socket ("ftp:\\ftp.heise.de", 21);
m_inStream = m_socket.getInputStream();
m_outStream = m_socket.getOutputStream();
String request = "ftp ftp.heise.de\nUSER anonymous\nPASS guest\n
TYPE I\nPASV\n";
Up to here everything's going well; the connection gets established and
the last response from the server is what has to be expected:
227 Entering passive mode <193,99,144,79,122,164>
From the above line I extract the raw IP-address and put it in a byte
buffer named address, so that
rawIP[0] = 193
rawIP[1] = 99
rawIP[2] = 144
rawIP[3] = 79
I construct a portnumber by the last two numbers:
portnumber = 122 * 255 + 164;
Then I try to construct a new socket:
InetAddress addr = InetAddress.getByAddress(rawIP);
Socket dataSocket = new Socket (addr, portnumber);
At this point an exception is thrown:
java.net.Connectexception: connection refused: connect.
The problem is not prohibited access to the server.
The building of the InetAddress seems correct, because
addr.getHostAddress() delivers ftp.heise.de
I'm not quite sure, if the building of the portnumber is correct. Does
anybody know some helpful hints ?
Xaver
I'm trying to write some code to download a file from a ftp server and
I'm not quite sure, if I have understood the FTP-RFC.
Code goes like this:
m_socket = new Socket ("ftp:\\ftp.heise.de", 21);
m_inStream = m_socket.getInputStream();
m_outStream = m_socket.getOutputStream();
String request = "ftp ftp.heise.de\nUSER anonymous\nPASS guest\n
TYPE I\nPASV\n";
Up to here everything's going well; the connection gets established and
the last response from the server is what has to be expected:
227 Entering passive mode <193,99,144,79,122,164>
From the above line I extract the raw IP-address and put it in a byte
buffer named address, so that
rawIP[0] = 193
rawIP[1] = 99
rawIP[2] = 144
rawIP[3] = 79
I construct a portnumber by the last two numbers:
portnumber = 122 * 255 + 164;
Then I try to construct a new socket:
InetAddress addr = InetAddress.getByAddress(rawIP);
Socket dataSocket = new Socket (addr, portnumber);
At this point an exception is thrown:
java.net.Connectexception: connection refused: connect.
The problem is not prohibited access to the server.
The building of the InetAddress seems correct, because
addr.getHostAddress() delivers ftp.heise.de
I'm not quite sure, if the building of the portnumber is correct. Does
anybody know some helpful hints ?
Xaver