FTP上传客户端

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();
    }
}

转载于:https://my.oschina.net/u/3543894/blog/1186565

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值