I've make a socket on Port 21 (FTP-Server). I make getInputStream and
getOutputStream. I send commands - and get's answers - best
but !
when I try to do a "LIST"-Command or a "get file" Command I get the
answer (from FTP-Server):
no data connection
Whats that? What can I do?
Thanks for HELP !
I read something about the "PORT" - Command . Must I perhaps use this
- how ?
Sorry about my englisch - its bad
Anja
Hi Anja,
have a lok at http://www.gamelan.com. There are several FTP clients with
source code available. Why to reinvent the wheel?
I think your problem is, that you either close the connection, or you
defined the stream objects within a method and not global to the object.
Regards,
Steffen Krug
Mail: steffe...@usa.net
Tel.: +49 172 6800933
JAVA consulting & programming
Anja Moessbauer wrote:
> I've make a socket on Port 21 (FTP-Server). I make getInputStream and
> getOutputStream. I send commands - and get's answers - best
> but !
> when I try to do a "LIST"-Command or a "get file" Command I get the
> answer (from FTP-Server):
> no data connection
>
> Whats that? What can I do?
> Thanks for HELP !
>
> I read something about the "PORT" - Command . Must I perhaps use this
> - how ?
>
> Sorry about my englisch - its bad
> Anja
FTP actually uses TWO ports, one for the commands (21) and a second
to pipe the file, which is what the PORT command is for.
The format of the PORT command is:
PORT xx,xx,xx,xx,yy,yy
where xx,xx,xx,xx is the IP address with comma replacing periods.
The yy parts are the port number. You can
obtain these with the "0" constructor for ServerSocket. From there,
use getLocalPort() to get the port number and the bit shifting below
to split that into its two eight bit components.
// Setup the data transfer Socket
ServerSocket listenSocket = new ServerSocket(0);/* 0 is an anonymous
port number*/
int dataPort = listenSocket.getLocalPort();
String hostName = InetAddress.getLocalHost().getHostAddress();
hostName = hostName.replace('.', ',');
this.listenAddr = hostName + "," +
((dataPort >> 8) & 0xFF) + "," +
(dataPort & 0xFF);
// Tell server where to send or get data
// here, cout is assumed to be the command output stream.
cout.println("PORT "+this.listenAddr);
// check various server responses...
From here, you need to send the server the "RETR" command and
IF the server response is ok (125, 150, or 200), then you can actually
proceed with getting the file from the listenSocket:
Socket dataSocket = listenSocket.accept();
InputStream ReceivedInputStream is = dataSocket.getInputStream();
For additional information, you should take a look at the official
FTP spec at:
ftp://nic.merit.edu/documents/rfc/rfc0959.txt
...and you will learn far more about FTP than anyone really cares to
know! :-)
PS- Your English is fine!
--
+++++++++++++++++++++++++++++++++++++++++++++++++++++
JoAnn P. Brereton
IBM Media and Telecommunications Solutions
REMOVE NOSPAM to reply.
+++++++++++++++++++++++++++++++++++++++++++++++++++++