SSH and hostgator, connection exception
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)
String lfile= localName;
String password = "xxxxxxx";
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, 2222);
java.util.Properties config = new java.util.Properties();
boolean ptimestamp = true;
// exec 'scp -t rfile' remotely
String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
// get I/O streams for remote scp
File _lfile = new File(lfile);
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");
// send "C0644 filesize filename", where filename should not include '/'
command="C0644 "+filesize+" ";
// send a content of lfile
byte buf=new byte;
int len=fis.read(buf, 0, buf.length);
out.write(buf, 0, len); //out.flush();
// send '\0'
buf=0; out.write(buf, 0, 1); out.flush();