Sending files through ftp is a piece of cake, or so I thought with all the commons net libraries around. I had to spend a few hours trying with apache commons net library and finally did it through sun.net.ftp.FtpClient. Below is the full code for anyone who needs it, without all the log messages.
TelnetOutputStream fos = null;
BufferedOutputStream bos = null;
FileInputStream theFile = null;
BufferedInputStream bis = null;
FtpClient ftp = null;
try
{
ftp = new FtpClient();
ftp.openServer("FTP_SERVER");
ftp.login("FTP_USER", "FTP_PASSWORD");
ftp.cd("REMOTE_DIR");
fos = ftp.put("REMOTE_FILENAME");
bos = new BufferedOutputStream(fos);
theFile = new FileInputStream("LOCAL_FOLDER" + "/" + "LOCAL_FILENAME");
bis = new BufferedInputStream(theFile,1000000);
byte buffer[] = new byte[1000000];
int i;
while ((i = bis.read(buffer)) != -1)
{
bos.write(buffer,0,i);
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (bis != null) bis.close();
if (theFile != null) theFile.close();
if (bos != null) bos.flush();
if (bos != null) bos.close();
if (fos != null) fos.flush();
if (fos != null) fos.close();
if (ftp != null) ftp.closeServer();
}