/**
*
* Java operation FTP Download
* File download.
*
*/
private void Ftpdownload ()
{
FtpClient ftpclient = null;
InputStream input = null;
Boolean loginflag = false;
list<string> list = new arraylist<string> ();
Try
{
int defaultport = Commonsmessage.ftp_default_port; 21st
int timeout = M400constant.num_sixty_thousand * M400CONSTANT.NUM_TWO; 120000
FtpClient = new FtpClient ();
Ftpclient.setdefaultport (Defaultport);
Ftpclient.setconnecttimeout (timeout);
Ftpclient.setsotimeout (timeout);
Ftpclient.setdefaulttimeout (timeout);
Ftpclient.setdatatimeout (timeout);
Ftpclient.setcontrolencoding ("UTF-8");
Ftpclientconfig conf = new Ftpclientconfig (Ftpclientconfig.syst_unix);
Conf.setserverlanguagecode ("en");
CONF.SETDEFAULTDATEFORMATSTR ("MMM dd hh:mm");
Ftpclient.configure (conf);
Ftpclient.connect (Systemconfig.getkey ("Scpftpip"));
Loginflag = Ftpclient.login (Systemconfig.getkey ("Scpftpusername"). Trim (),
Systemconfig.getkey ("Scpftppassword"). Trim ());
String FTPDir = Systemconfig.getkey ("Ftphangupdir"). Trim ();
if (!loginflag)
{
Debugger.debug ("Login SCP FTP is:" + loginflag);
}
String FTPDir = Systemconfig.getkey ("Ftphangupdir"). Trim ();
if (Ftpclient.changeworkingdirectory (FTPDir))
{
Ftpfile file[] = ftpclient.listfiles (FTPDir);
if (file!= null && file.length > 0)
{
Debugger.debug ("Hungup File size is:" + file.length);
for (int i = 0; i < file.length; i++)
{
String fileName = File[i].getname ();
Ftpclient.setbuffersize (commonsmessage.one_k_buffer_size);
Set file type (binary)
Ftpclient.setfiletype (Ftp.binary_file_type);
input = Ftpclient.retrievefilestream (fileName);
ProcessInput (ftpclient, input, list, fileName);
if (Downflag) {
Ftpclient.deletefile (FileName);
// }
}
}
Else
{
Try
{
Thread.Sleep (M400constant.num_five_thousand);
}
catch (Interruptedexception e)
{
/*
* IF (debugger.isdebugenable ()) {
* Debugger.debug ("Failed to Queryscptoquery", e); }
*/
Error ("Failed to Queryscptoquery", e);
}
}
}
Else
{
Debugger.debug ("SCP dir is error");
}
}
catch (Exception e)
{
/*
* Debugger.debug ("Dowonload file is Faild", e);
*/
Error ("Dowonload file is Faild", e);
}
Finally
{
Close (input, "Close InputStream is Faild");
if (ftpclient!= null)
{
Try
{
DeleteFile (ftpclient, list);
Boolean logoutflag = false;
Try
{
Logoutflag = Ftpclient.logout ();
Debugger.debug ("Logout:" + Logoutflag);
}
catch (Exception e)
{
/*
* Debugger.debug ("logout:" + Logoutflag);
*/
Error ("Logout:" + Logoutflag, E);
}
FtpClient = null;
}
catch (Exception e)
{
/*
* IF (debugger.isdebugenable ()) {
* Debugger.error ("Failed to Ftpdownload", e); }
*/
Error ("Failed to Ftpdownload", e);
}
try {
Ftpclient.disconnect ();
catch (IOException e) {
if (debugger.isdebugenable ()) {
Debugger.debug ("Failed to Ftpdownload", e);
// }
// }
}
}
}
/**
* Processing ftp corresponding file input stream.
*
* @param ftpclient
* FTP Client Object
* @param input
* FTP File input stream
* @param list
* A list of processed files used to perform file deletion
* @param fileName
* The name of the file currently processed
*/
private void ProcessInput (ftpclient ftpclient, InputStream input, list<string> List, String fileName)
{
if (input = = null)
{
Return
}
Boolean downflag = Callingservice (input);
Callingservice (input);
Try
{
Input.close ();
Ftpclient.completependingcommand ();
List.add (FileName);
}
catch (Exception e)
{
/*
* Debugger.debug ("Failed to Ftpdownload", e);
*/
Error ("Failed to Ftpdownload", e);
}
}
}