Sorry, put this in the wrong forum section(my first time on the forums) and I couldn't figure out how to delete the one I put in the file IO section. But anyway, my problem:

I'm writing some code to take from pictures on my local computer and pushing them up to a hostgator account using JSCH and SSH. My code works to an extent, but after successfully putting up roughly 10 images, I start getting an exception for each attempt after the 10; com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect

I am very new to JSCH and basically just rewrote some example code that was provided by JSCH. The fact that it works for the first few images makes me believe it may be something on hostgator's end, but if anyone has any other ideas I'll gladly listen.

The following is the method I call to move each image up to hostgator. I figure I may be making a mistake by creating a session each time I send an image, but I was just working with the example code as best as I could to keep things simple.
So if anyone has any previous experience with something like this or can offer advice in the right direction, I'll take whatever I can get. Thanks in advance

public static void movePicture(String localName, String remoteName)
	 {
		 FileInputStream fis=null;
		 try
		 {
			 String lfile= localName;
			 String user="xxxx";
			 String host="xx.xx.xx.xx";
			 String rfile=remoteName;
			 String password = "xxxxxxx";
 
			 JSch jsch=new JSch();
			 Session session=jsch.getSession(user, host, 2222);
 
		     session.setPassword(password);
		     java.util.Properties config = new java.util.Properties(); 
		     config.put("StrictHostKeyChecking", "no");
		     session.setConfig(config);
		     session.connect();
 
		     boolean ptimestamp = true;
 
		     // exec 'scp -t rfile' remotely
		     String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
		     Channel channel=session.openChannel("exec");
		     ((ChannelExec)channel).setCommand(command);
 
		     // get I/O streams for remote scp
		     OutputStream out=channel.getOutputStream();
		     InputStream in=channel.getInputStream();
 
		     channel.connect();
 
		     if(checkAck(in)!=0){
		    	 System.exit(0);
		     }
 
		     File _lfile = new File(lfile);
 
		     if(ptimestamp)
		     {
		    	 command="T "+(_lfile.lastModified()/1000)+" 0";
		    	 // The access time should be sent here,
		    	 // but it is not accessible with JavaAPI ;-<
		    	 command+=(" "+(_lfile.lastModified()/1000)+" 0\n"); 
		    	 out.write(command.getBytes()); out.flush();
		    	 if(checkAck(in)!=0)
		    		 System.exit(0);
		     }
 
		     // send "C0644 filesize filename", where filename should not include '/'
		     long filesize=_lfile.length();
		     command="C0644 "+filesize+" ";
		     if(lfile.lastIndexOf('/')>0)
		    	 command+=lfile.substring(lfile.lastIndexOf('/')+1);
		     else
		    	 command+=lfile;
 
		     command+="\n";
		     out.write(command.getBytes()); out.flush();
		     if(checkAck(in)!=0)
		    	 System.exit(0);
 
		     // send a content of lfile
		     fis=new FileInputStream(lfile);
		     byte[] buf=new byte[1024];
		     while(true)
		     {
		    	 int len=fis.read(buf, 0, buf.length);
		    	 if(len<=0) break;
		    	 out.write(buf, 0, len); //out.flush();
		     }
		     fis.close();
		     fis=null;
		     // send '\0'
		     buf[0]=0; out.write(buf, 0, 1); out.flush();
 
		     if(checkAck(in)!=0)
		    	 System.exit(0);
 
		     out.close();
 
		     channel.disconnect();
		     session.disconnect();
		 }
		 catch(Exception e){
			 System.out.println(e);
			 try{if(fis!=null)fis.close();}catch(Exception ee){}
		 }
	 }