FTP上传客户端
import java.io.File;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.chinamobile.www.service.FTPUint;
import com.chinamobile.www.util.FileUtil;
public class UpLoadFileByFTP {
private Logger logger = Logger.getLogger(this.getClass().getName());
public void uploadfile(){
int failCount = 0;
String configPath = "/conf/serviceConf.properties";
// System.out.println(configPath);
// Properties prop = FileUtil.loadProperties(configPath);
logger.info("Setting Environment Variables");
String ftp_address = "146.11.40.40";// prop.getProperty("ftp_address");
String ftp_port = "22";// prop.getProperty("ftp_port");
String ftp_user = "root";// prop.getProperty("ftp_user");
String ftp_psw = "root000";//prop.getProperty("ftp_psw");
String ftp_server_path ="/home";// prop.getProperty("ftp_server_path");
logger.info("ftp_address:" + ftp_address);
FTPUint ftp = FTPUint.getInstance(ftp_address, Integer.parseInt(ftp_port));
ftp.connectAndLogin(ftp_user, ftp_psw);
File file = new File("c:\\local_data\\test.csv");
ftp.changeWorkDirectory(ftp_server_path);
boolean result = ftp.storeFileToServer(file, "test.csv");
if(!result){
failCount++;
}
if(failCount==10){
System.out.println(result);
ftp.logout();
//调用发送失败服务
}
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
UpLoadFileByFTP TEST = new UpLoadFileByFTP();
TEST.uploadfile();
}
}