Java Code Examples for org.apache.commons.net.ftp.FTPFile#setName()

The following examples show how to use org.apache.commons.net.ftp.FTPFile#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FTPClientUtils.java    From springboot-ureport with Apache License 2.0 6 votes vote down vote up
/**
 *  获取全部的文件列表
 * @param path 路径
 * @return
 */
public List<FTPFile> getFileList(String path){
	List<FTPFile> list = new ArrayList<>();
	FTPClient ftpClient = borrowObject();
	try {
		FTPFile[] listFiles = ftpClient.listFiles(path);
		for (FTPFile ftpFile : listFiles) {
			byte[] bytes = ftpFile.getName().getBytes("iso-8859-1");
			ftpFile.setName(new String(bytes, "GBK"));
			list.add(ftpFile);
		}
	} catch (IOException e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}finally {
		returnObject(ftpClient);
	}
	return  list;
}
 
Example 2
Source File: PooledFTPOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Implementation using the MLST command, if available. 
 * 
 * @param targetUri
 * @param ftp
 * @return
 */
private Info info(URI targetUri, FTPClient ftp) {
	try {
		if (ftp.hasFeature(FTPCmd.MLST.getCommand())) {
			// Pure-FTPd does not understand .. and . in the path, hence we use URI.normalize()
			String path = getPath(targetUri.normalize());
			if (path.equals(URIUtils.PATH_SEPARATOR)) {
				// CLO-4118: root directory, GlobalScape EFT disallows MLST
				FTPFile root = new FTPFile();
				root.setType(FTPFile.DIRECTORY_TYPE);
				root.setName("");
				return info(root, null, targetUri);
			}
			FTPFile file = mlistFile(ftp, path);
			if (file != null) {
				return new FTPInfo(file, null, targetUri);
			} else {
				return null;
			}
		}
	} catch (IOException ioe) {
		log.debug(MessageFormat.format("File metadata reading failed: {0}", targetUri), ioe);
	}
	
	return infoFallback(targetUri, ftp);
}
 
Example 3
Source File: TestMainframeDatasetInputFormat.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  format = new MainframeDatasetInputFormat<SqoopRecord>();
  mockFTPClient = mock(FTPClient.class);
  MainframeFTPClientUtils.setMockFTPClient(mockFTPClient);
  try {
    when(mockFTPClient.login("user", "pssword")).thenReturn(true);
    when(mockFTPClient.logout()).thenReturn(true);
    when(mockFTPClient.isConnected()).thenReturn(true);
    when(mockFTPClient.completePendingCommand()).thenReturn(true);
    when(mockFTPClient.changeWorkingDirectory(anyString())).thenReturn(true);
    when(mockFTPClient.getReplyCode()).thenReturn(200);
    when(mockFTPClient.getReplyString()).thenReturn("");
    when(mockFTPClient.noop()).thenReturn(200);
    when(mockFTPClient.setFileType(anyInt())).thenReturn(true);

    FTPFile ftpFile1 = new FTPFile();
    ftpFile1.setType(FTPFile.FILE_TYPE);
    ftpFile1.setName("test1");
    FTPFile ftpFile2 = new FTPFile();
    ftpFile2.setType(FTPFile.FILE_TYPE);
    ftpFile2.setName("test2");
    FTPFile[] ftpFiles = { ftpFile1, ftpFile2 };
    when(mockFTPClient.listFiles()).thenReturn(ftpFiles);
  } catch (IOException e) {
    fail("No IOException should be thrown!");
  }
}
 
Example 4
Source File: FtpFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
FTPFilePathIterator(String folder, FTPFile filesArr[]) {
	prefix = folder != null ? folder + "/" : "";
	files = new ArrayList<FTPFile>();
	for (FTPFile ftpFile : filesArr) {
		if(!ftpFile.isDirectory()) {
			ftpFile.setName(prefix + ftpFile.getName());
			files.add(ftpFile);
		}
	}
}
 
Example 5
Source File: TestMainframeDatasetFTPRecordReader.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws IOException {
  mockFTPClient = mock(FTPClient.class);
  MainframeFTPClientUtils.setMockFTPClient(mockFTPClient);
  try {
    when(mockFTPClient.login("user", "pssword")).thenReturn(true);
    when(mockFTPClient.logout()).thenReturn(true);
    when(mockFTPClient.isConnected()).thenReturn(true);
    when(mockFTPClient.completePendingCommand()).thenReturn(true);
    when(mockFTPClient.changeWorkingDirectory(anyString())).thenReturn(true);
    when(mockFTPClient.getReplyCode()).thenReturn(200);
    when(mockFTPClient.noop()).thenReturn(200);
    when(mockFTPClient.setFileType(anyInt())).thenReturn(true);

    FTPFile ftpFile1 = new FTPFile();
    ftpFile1.setType(FTPFile.FILE_TYPE);
    ftpFile1.setName("test1");
    FTPFile ftpFile2 = new FTPFile();
    ftpFile2.setType(FTPFile.FILE_TYPE);
    ftpFile2.setName("test2");
    FTPFile[] ftpFiles = { ftpFile1, ftpFile2 };
    when(mockFTPClient.listFiles()).thenReturn(ftpFiles);

    when(mockFTPClient.retrieveFileStream("test1")).thenReturn(
        new ByteArrayInputStream("123\n456\n".getBytes()));
    when(mockFTPClient.retrieveFileStream("test2")).thenReturn(
        new ByteArrayInputStream("789\n".getBytes()));
    when(mockFTPClient.retrieveFileStream("NotComplete")).thenReturn(
        new ByteArrayInputStream("NotComplete\n".getBytes()));
  } catch (IOException e) {
    fail("No IOException should be thrown!");
  }

  JobConf conf = new JobConf();
  conf.set(DBConfiguration.URL_PROPERTY, "localhost:" + "11111");
  conf.set(DBConfiguration.USERNAME_PROPERTY, "user");
  conf.set(DBConfiguration.PASSWORD_PROPERTY, "pssword");
  // set the password in the secure credentials object
  Text PASSWORD_SECRET_KEY = new Text(DBConfiguration.PASSWORD_PROPERTY);
  conf.getCredentials().addSecretKey(PASSWORD_SECRET_KEY,
      "pssword".getBytes());
  conf.setClass(DBConfiguration.INPUT_CLASS_PROPERTY, DummySqoopRecord.class,
      DBWritable.class);

  Job job = new Job(conf);
  mfDIS = new MainframeDatasetInputSplit();
  mfDIS.addDataset("test1");
  mfDIS.addDataset("test2");
  context = mock(TaskAttemptContext.class);
  when(context.getConfiguration()).thenReturn(job.getConfiguration());
  mfDFTPRR = new MainframeDatasetFTPRecordReader();
}
 
Example 6
Source File: FtpFileSystem.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public FTPFile toFile(String filename) throws FileSystemException {
	FTPFile ftpFile = new FTPFile();
	ftpFile.setName(filename);
	return ftpFile;
}