Page 1 of 1

Java Uploader

Posted: Tue Feb 06, 2007 2:26 pm
by shiznatix
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:

Code: Select all

//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
private synchronized boolean Upload(File TheFile, String FileName) throws IOException
{
	DataSocket = GetPassiveDataSocket();		
	SendCommand("STOR " + FileName + "\r\n");
	String Response = GetResponse();
	
	if (!Response.startsWith("150") && !Response.startsWith("125"))
	{
		return false;
	}
	
	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 = new byte[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();
	
	return true;
}


Posted: Tue Feb 06, 2007 3:49 pm
by shiznatix
never mind. i didnt have enough space left on my FTP account so of course it was doing that. sigh.