applet / ftp transfer

J

Jonathan Mcdougall

Hi,

I am writing an applet which should transfer a given file using ftp to
the server. Simply posting it does not work because of php's timeout
setting and anyways a 3 minute long blank page is not quite
interesting nor user-friendly for a client.

The thing worked for a while, but now it seems to exhibit some
undefined behavior. Posting the whole code here would not be
pertinent, so I will try to be as clear as possible.

The applet starts a thread (sun's swingWorker) which connects to the
server using a socket through port 21 :


Socket echoSocket = new Socket(host, 21);

PrintStream os = new PrintStream(echoSocket.getOutputStream());
DataInputStream is = new DataInputStream(echoSocket.getInputStream());


Now, after each ftp command, I call this function (exception handling
removed)


private int getreply(DataInputStream is)
{
BufferedReader d = new BufferedReader(new InputStreamReader(is));

String sockoutput;

do
{
sockoutput = d.readLine();

} while(!(Character.isDigit(sockoutput.charAt(0)) &&
Character.isDigit(sockoutput.charAt(1)) &&
Character.isDigit(sockoutput.charAt(2)) &&
sockoutput.charAt(3) == ' '));

return(Integer.parseInt(sockoutput.substring(0, 3)));
}


which returns the response from the server. I am now ready to send
ftp commands :

// logs in
os.println("user username");
getreply(is);

os.println("pass password");
getreply(is);

ServerSocket serverSocket = new ServerSocket(0);

// issues a port command, function body is not pertinent
port(serverSocket, is, os);
getreply(

os.println("type i");
getreply(is);

os.println("cwd " + targetpath);
getreply(is);

os.println("stor " + filename);

int result = getreply(is);


Everything goes well until the last line. getreply() never returns;
it stops on that line :

sockoutput = d.readLine();

And that puzzles me, since it _has_ worked a while ago and I don't
remember changing anything to the code.

What's more, I tested it on three different machines.
Windows XP : worked!!!
Windows 2000 : failed
Windows 98 : failed

The xp box made it work, I don't know why.

I know this is no easy nor interesting question (I would probably not
bother reading it), but I need help. While this is not an *urgent*
question, I would appreciate a quick answer, though I know my time is
not more valuable than yours.

Thank you,


Jonathan Mcdougall
(e-mail address removed)
 
V

Van Glass

Jonathan,

Since it worked on one machine out of three it could be that it is
using active mode instead of passive mode for data transfer. If for
example the two machines it failed on are behind a firewall then you
must use passive mode data transfer. I would check to see if active
or passive mode is used. From the code you submitted it looks like
active mode is used. Consider changing to use passive mode and see if
that works.

See FTP Applet at http://www.jscape.com/ftpapplet/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,350
Latest member
fadmo

Latest Threads

Top