ftp util
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: NetFTP.java
package kr.co.raysystem.util;
import com.oreilly.servlet.MultipartRequest;
import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import kr.co.raysystem.common.UniqueFileRenamePolicy;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class NetFTP
{
public NetFTP()
{
FTP_ID = "tmax";
FTP_PASS = "tmax";
FTP_IP = new String();
}
public void XMLFileUPLoad(HttpServletRequest request, String fileName, String path, String FTPPath)
{
ArrayList list = new ArrayList();
list.add("203.128.238.174");
list.add("203.128.238.175");
if(request.getLocalAddr() != null && request.getLocalAddr().equals("98.0.38.88")){
FTP_IP = "98.0.38.89";
FTP_PASS = "qhdks@89";
}else{
FTP_IP = "98.0.38.88";
FTP_PASS = "qhdks@88";
}
execute(FTP_IP, FTP_ID, FTP_PASS, fileName, path, FTPPath, true);
//for(int i = 0; i < list.size(); i++)
// execute(list.get(i).toString(), FTP_ID, FTP_PASS, fileName, path, FTPPath, true);
}
public MultipartRequest fileUpload(HttpServletRequest request, String path, String FTPPath)
{
int sizeLimit = 0x7a1aca00;
if(request.getLocalAddr() != null && request.getLocalAddr().equals("98.0.38.88")){
FTP_IP = "98.0.38.89";
FTP_PASS = "qhdks@89";
}else{
FTP_IP = "98.0.38.88";
FTP_PASS = "qhdks@88";
}
MultipartRequest multi = null;
Enumeration formNames = null;
String formName = null;
String Cfile[] = (String[])null;
try
{
UniqueFileRenamePolicy dfrp = new UniqueFileRenamePolicy();
multi = new MultipartRequest(request, path, sizeLimit, "euc-kr", dfrp);
ArrayList newFile = new ArrayList();
for(formNames = multi.getFileNames(); formNames.hasMoreElements();)
{
formName = (String)formNames.nextElement();
newFile.add(multi.getFilesystemName(formName));
File file = multi.getFile(formName);
HttpSession session = request.getSession(true);
if(file != null)
session.setAttribute("RAY_FILESIZE", String.valueOf(file.length()));
}
Cfile = new String[newFile.size()];
for(int i = 0; i < newFile.size(); i++)
if(newFile.get(i) == null)
{
Cfile[i] = "";
} else
{
Cfile[i] = (String)newFile.get(i);
execute(FTP_IP, FTP_ID, FTP_PASS, Cfile[i], path, FTPPath, true);
}
}
catch(IOException e)
{
System.out.println(e.toString());
e.printStackTrace();
}
return multi;
}
public void delete(HttpServletRequest request, String path, String FTPPath)
{
if(request.getLocalAddr() != null && request.getLocalAddr().equals("98.0.38.88")){
FTP_IP = "98.0.38.89";
FTP_PASS = "qhdks@89";
}else{
FTP_IP = "98.0.38.88";
FTP_PASS = "qhdks@88";
}
File file = new File(path);
if(file.exists())
file.delete();
execute(FTP_IP, FTP_ID, FTP_PASS, null, path, FTPPath, false);
}
public void execute(String rmoteServerIP, String id, String pass, String filename, String path, String FTPPath, boolean flag)
{
FTPClient ftpClient = null;
try
{
ftpClient = new FTPClient();
ftpClient.setControlEncoding("euc-kr");
System.out.println("rmoteServerIP:["+rmoteServerIP+"]");
ftpClient.connect(rmoteServerIP);
int reply = ftpClient.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply))
{
ftpClient.disconnect();
} else
{
ftpClient.setSoTimeout(10000);
ftpClient.login(id, pass);
ftpClient.setFileType(2);
ftpClient.setFileTransferMode(10);
if(flag)
{
boolean result = false;
InputStream inputStream = null;
java.io.OutputStream outputStream = null;
File put_file = new File(path + File.separator + filename);
inputStream = new FileInputStream(put_file);
ftpClient.makeDirectory(FTPPath);
ftpClient.changeWorkingDirectory(FTPPath);
result = ftpClient.storeFile(put_file.getName(), inputStream);
inputStream.close();
if(result)
System.out.println("put successful");
else
System.out.println("put failure!");
} else
{
ftpClient.deleteFile(FTPPath);
}
System.out.println(path + File.separator + filename);
System.out.println("FTP \uD30C\uC77C\uACBD\uB85C " + FTPPath);
ftpClient.logout();
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
if(ftpClient != null && ftpClient.isConnected())
try
{
ftpClient.disconnect();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
private String FTP_ID;
private String FTP_PASS;
private String FTP_IP;
}
'JAVA' 카테고리의 다른 글
[JAVA]HASHMAP 돌리기(SORT) (0) | 2017.11.24 |
---|---|
[JAVA]getBean Test Main (0) | 2017.11.24 |
[JAVA]filter에서 파라미터 받기 (1) | 2017.11.23 |
[JAVA]Filter를 이용한 request 파라미터 변경 방법 (0) | 2017.11.23 |
[JAVA]Filter를 이용한 multipart/form-data 처리 및 파일 업로드 처리 (0) | 2017.11.23 |