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)
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)