FTP Upload Problems.

Ok so I am writing this small FTP applet so I can upload files to my website. All is going well except when I upload a large file, it uploads then as soon as its done uploading it disappears. I have no idea why. If the file is above about 3/4 a meg then it just disappears when its done uploading. I can watch it from another FTP program and see it being uploaded (I just see the tmp file thats created) and I see the file size get bigger and bigger until when its done the file no loger exists. There is never a problem for a file thats smaller.

I was hoping that someone could shed some light as to why this is happening. Here is the relivent code:

//the code that calls everything

Connect(Engine.Model.FTPHost, Engine.Model.FTPPort);

Login(Engine.Model.FTPUser, Engine.Model.FTPPass);

ChangeDirectory(Engine.Model.UploadDirectory);

SetDataType("I");

Upload(Engine.Model.Que[i], Engine.Model.Que[i].getName());

Disconnect();

//end

//the Upload method

privatesynchronizedboolean Upload(File TheFile, String FileName)throws IOException

{

DataSocket = GetPassiveDataSocket();

SendCommand("STOR " + FileName +"\r\n");

String Response = GetResponse();

if (!Response.startsWith("150") && !Response.startsWith("125"))

{

returnfalse;

}

BufferedInputStream BufferedInput =new BufferedInputStream(new FileInputStream(TheFile));

BufferedOutputStream BufferedOutput = DataSocket.GetOutputStream();

float FileSize = TheFile.length();

float PercentPerIteration = 100 / FileSize;

int BytesRead = 0;

int BufferSize = 1024;

byte[] Buffer =newbyte[BufferSize];

int CurrentByte;

while (((CurrentByte = BufferedInput.read(Buffer)) != -1) && Engine.Model.AllowToRun)

{

BytesRead = BytesRead + BufferSize;

float Percent = PercentPerIteration * BytesRead;

Engine.View.SetProgressBarValue((int)Percent);

BufferedOutput.write(Buffer, 0, CurrentByte);

}

BufferedInput.close();

BufferedOutput.close();

returntrue;

}

[3250 byte] By [shiznatixa] at [2007-11-26 17:32:04]
# 1
Too many unknown, and non-standard, elements in your code.Post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
hiwaa at 2007-7-9 0:00:04 > top of Java-index,Archived Forums,Socket Programming...
# 2

Your Web server probably has an upload size limit (10Mb on mine), but there are other problems here:

> float PercentPerIteration = 100 / FileSize;

Fallacious. You can't know the percent of the file per read iteration in advance of the read iterations.

> int BufferSize = 1024;

Raise this to at least 16k, better stil 32k or 64k, and get rid of the BufferedInput/OutputStreams.

> int CurrentByte;

Very poor name for this variable. It should be something like 'readCount' based on how you're using it.

> BytesRead = BytesRead + BufferSize;

Fallacious. The number of bytes you have read should be incremented by the actual readCount, not the buffer size.

>float Percent = PercentPerIteration * BytesRead;

Fallacious. Percent = (BytesRead*100.0)/FileSize;

ejpa at 2007-7-9 0:00:04 > top of Java-index,Archived Forums,Socket Programming...