package com.trs.project.utils;

import cn.hutool.core.io.FileUtil;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;
import com.trs.project.entity.BusinessInfo;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

@Component
public class SpringSFTPUtils {
    public List<String> getFTPList() throws Exception {
        String  cust="BEA_000004_F_C_20120420182012_ALL.dat";
        String  regex=".*";
        String fileUrl = "C:/Users/ZHENG/Desktop/FTP/file/";
        System.err.println(cust.matches(regex));
        //tempFileName.matches(dataFileRegex)
        ChannelSftp sftp= new ChannelSftp();
        SFTPUtils sftpUtils  =  new SFTPUtils("119.254.15.195", 22321, "nmgsl", "EtDRPjdSVU");
        Vector<?> objects = sftpUtils.listFiles("/data/trs_cust/data/ENT/20230111", sftpUtils.sftp);
        List<String> nameString = new ArrayList<String>();
        for (Object object : objects) {
            String[] s = object.toString().split(" ");
            String fileName = s[s.length - 1];
            if(!fileName.equals(".") && !fileName.equals("..")){
                nameString.add(fileName);
            }
        }
        sftpUtils.disconnect(sftpUtils.sftp, sftpUtils.sshSession, sftpUtils.channel);
        return nameString;
    }
}
