當前位置: 首頁>>代碼示例>>Java>>正文


Java FTPFile類代碼示例

本文整理匯總了Java中org.apache.commons.net.ftp.FTPFile的典型用法代碼示例。如果您正苦於以下問題:Java FTPFile類的具體用法?Java FTPFile怎麽用?Java FTPFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FTPFile類屬於org.apache.commons.net.ftp包,在下文中一共展示了FTPFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileStatus

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
/**
 * Convert the file information in FTPFile to a {@link FileStatus} object. *
 * 
 * @param ftpFile
 * @param parentPath
 * @return FileStatus
 */
private FileStatus getFileStatus(FTPFile ftpFile, Path parentPath) {
  long length = ftpFile.getSize();
  boolean isDir = ftpFile.isDirectory();
  int blockReplication = 1;
  // Using default block size since there is no way in FTP client to know of
  // block sizes on server. The assumption could be less than ideal.
  long blockSize = DEFAULT_BLOCK_SIZE;
  long modTime = ftpFile.getTimestamp().getTimeInMillis();
  long accessTime = 0;
  FsPermission permission = getPermissions(ftpFile);
  String user = ftpFile.getUser();
  String group = ftpFile.getGroup();
  Path filePath = new Path(parentPath, ftpFile.getName());
  return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
      accessTime, permission, user, group, filePath.makeQualified(this));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:24,代碼來源:FTPFileSystem.java

示例2: download

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
public static byte[] download(String url, int port, String username, String password, String remotePath,
		String fileName) throws IOException {
	FTPClient ftp = new FTPClient();
	ftp.setConnectTimeout(5000);
	ftp.setAutodetectUTF8(true);
	ftp.setCharset(CharsetUtil.UTF_8);
	ftp.setControlEncoding(CharsetUtil.UTF_8.name());
	try {
		ftp.connect(url, port);
		ftp.login(username, password);// 登錄
		if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
			ftp.disconnect();
			throw new IOException("login fail!");
		}
		ftp.changeWorkingDirectory(remotePath);
		ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
		FTPFile[] fs = ftp.listFiles();
		for (FTPFile ff : fs) {
			if (ff.getName().equals(fileName)) {
				try (ByteArrayOutputStream is = new ByteArrayOutputStream();) {
					ftp.retrieveFile(ff.getName(), is);
					byte[] result = is.toByteArray();
					return result;
				}
			}
		}

		ftp.logout();
	} finally {
		if (ftp.isConnected()) {
			ftp.disconnect();
		}
	}
	return null;
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:36,代碼來源:FTPUtil.java

示例3: getMaxFileName

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
/** 獲得目錄下最大文件名 */
public String getMaxFileName(String remotePath) {
	try {
		ftpClient.changeWorkingDirectory(remotePath);
		FTPFile[] files = ftpClient.listFiles();
		Arrays.sort(files, new Comparator<FTPFile>() {
			public int compare(FTPFile o1, FTPFile o2) {
				return o2.getName().compareTo(o1.getName());
			}
		});
		return files[0].getName();
	} catch (IOException e) {
		logger.error("", e);
		throw new FtpException("FTP訪問目錄[" + remotePath + "]出錯!", e);
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:17,代碼來源:FtpClient.java

示例4: listStatus

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
/**
 * Convenience method, so that we don't open a new connection when using this
 * method from within another method. Otherwise every API invocation incurs
 * the overhead of opening/closing a TCP connection.
 */
private FileStatus[] listStatus(FTPClient client, Path file)
    throws IOException {
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  FileStatus fileStat = getFileStatus(client, absolute);
  if (fileStat.isFile()) {
    return new FileStatus[] { fileStat };
  }
  FTPFile[] ftpFiles = client.listFiles(absolute.toUri().getPath());
  FileStatus[] fileStats = new FileStatus[ftpFiles.length];
  for (int i = 0; i < ftpFiles.length; i++) {
    fileStats[i] = getFileStatus(ftpFiles[i], absolute);
  }
  return fileStats;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:FTPFileSystem.java

示例5: parseFTPEntry

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
/**
 * Parses a line of an z/OS - MVS FTP server file listing and converts it
 * into a usable format in the form of an <code> FTPFile </code> instance.
 * If the file listing line doesn't describe a file, then
 * <code> null </code> is returned. Otherwise a <code> FTPFile </code>
 * instance representing the file is returned.
 *
 * @param entry
 *            A line of text from the file listing
 * @return An FTPFile instance corresponding to the supplied entry
 */
public FTPFile parseFTPEntry(String entry) {
    boolean isParsed = false;
    FTPFile f = new FTPFile();

    if (isType == FILE_LIST_TYPE) {
        isParsed = parseFileList(f, entry);
    } else if (isType == MEMBER_LIST_TYPE) {
        isParsed = parseMemberList(f, entry);
        if (!isParsed) {
            isParsed = parseSimpleEntry(f, entry);
        }
    } else if (isType == UNIX_LIST_TYPE) {
        isParsed = parseUnixList(f, entry);
    } else if (isType == JES_LEVEL_1_LIST_TYPE) {
        isParsed = parseJeslevel1List(f, entry);
    } else if (isType == JES_LEVEL_2_LIST_TYPE) {
        isParsed = parseJeslevel2List(f, entry);
    }

    if (!isParsed) {
        f = null;
    }

    return f;
}
 
開發者ID:kmarius,項目名稱:xdman,代碼行數:37,代碼來源:MVSFTPEntryParser.java

示例6: getTotalRemoteFileSize

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
private long getTotalRemoteFileSize(Collection<String> fileNames) {
	try {
		Future<Long> fileSizeResult = perform(() -> {
			return fileNames.stream()
					.map(rethrow((String fileName) -> {
						FTPFile[] ftpFiles = ftpClient.listFiles(fileName);
						if (ftpFiles.length != 1 || !ftpFiles[0].isFile()) {
							return 0L;
						} else {
							return ftpFiles[0].getSize();
						}
					}))
					.mapToLong(Long::valueOf)
					.sum();
		});
		return AsyncUtil.getResult(fileSizeResult);
	} catch (ExecutionException e) {
		LOGGER.warn("Error while calculating download file size, progress will not be available.");
		LogUtil.stacktrace(LOGGER, e);
		return 0;
	}
}
 
開發者ID:Azzurite,項目名稱:MinecraftServerSync,代碼行數:23,代碼來源:FTPSyncClient.java

示例7: downLoadFile

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
/**
 * 下載
 * 
 * @param remotePath 下載目錄
 * @param localPath 本地目錄
 * @return
 * @throws Exception
 */
public boolean downLoadFile(String remotePath, String localPath) throws FtpException {
	synchronized (LOCK) {
		try {
			if (ftpClient.changeWorkingDirectory(remotePath)) {// 轉移到FTP服務器目錄
				FTPFile[] files = ftpClient.listFiles();
				if (files.length > 0) {
					File localdir = new File(localPath);
					if (!localdir.exists()) {
						localdir.mkdir();
					}
				}
				for (FTPFile ff : files) {
					if (!downLoadFile(ff, localPath)) {
						return false;
					}
				}
				return files.length > 0;
			}
		} catch (IOException e) {
			logger.error("", e);
			throw new FtpException("FTP下載[" + localPath + "]出錯!", e);
		}
		return false;
	}
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:34,代碼來源:FtpClient.java

示例8: NetworkFile

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
public NetworkFile(NetworkFile dir, FTPFile file) {
	String name = file.getName();
	String dirPath = dir.getPath();
	host = dir.host;
	this.file = file;
	if (name == null) {
		throw new NullPointerException("name == null");
	}
	if (dirPath == null || dirPath.isEmpty()) {
		this.path = fixSlashes(name);
	} else if (name.isEmpty()) {
		this.path = fixSlashes(dirPath);
	} else {
		this.path = fixSlashes(join(dirPath, name));
	}
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:17,代碼來源:NetworkFile.java

示例9: testParseFTPEntryExpected

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Test
public void testParseFTPEntryExpected() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "drw-rw-rw-   1 user      ftp             0  Mar 11 20:56 ADMIN_Documentation");
    assertNotNull(parsed);
    assertEquals(parsed.getType(), FTPFile.DIRECTORY_TYPE);
    assertEquals("user", parsed.getUser());
    assertEquals("ftp", parsed.getGroup());
    assertEquals("ADMIN_Documentation", parsed.getName());

    parsed = parser.parseFTPEntry(
            "drwxr--r--   1 user     group          0 Feb 14 18:14 Downloads");
    assertNotNull(parsed);
    assertEquals("Downloads", parsed.getName());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:20,代碼來源:UnixFTPEntryParserTest.java

示例10: testCurrentYear

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Test
public void testCurrentYear() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1 20708    205             194 Oct 17 14:40 D3I0_805.fixlist");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(17, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(14, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(40, parsed.getTimestamp().get(Calendar.MINUTE));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:17,代碼來源:UnixFTPEntryParserTest.java

示例11: listFilesRecursively

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
private Map<String, FTPFile> listFilesRecursively(String directory) throws IOException {
	FTPFile[] listFiles = ftpClient.listFiles(directory);
	List<FTPFile> ftpFiles = Arrays.asList(listFiles);

	Map<String, FTPFile> fileMap = new HashMap<>();

	ftpFiles.stream()
			.filter(FTPFile::isFile)
			.filter(file -> !file.getName().endsWith(".md5"))
			.forEach(file -> {
				fileMap.put(directory + '/' + file.getName(), file);
			});

	ftpFiles.stream()
			.filter(FTPFile::isDirectory)
			.map(rethrow((FTPFile dir) -> listFilesRecursively(directory + '/' + dir.getName())))
			.forEach(fileMap::putAll);

	return fileMap;
}
 
開發者ID:Azzurite,項目名稱:MinecraftServerSync,代碼行數:21,代碼來源:FTPSyncClient.java

示例12: testLowerCaseMonths

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Test
public void testLowerCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "drwxrwxrwx    41 spinkb  spinkb      1394 jan 21 20:57 Desktop");
    assertNotNull(parsed);
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:18,代碼來源:UnixFTPEntryParserTest.java

示例13: testUpperCaseMonths

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Test
public void testUpperCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "drwxrwxrwx    41 spinkb  spinkb      1394 Feb 21 20:57 Desktop");
    assertNotNull(parsed);
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:17,代碼來源:UnixFTPEntryParserTest.java

示例14: queryChildDocuments

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
                                  String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final NetworkFile parent = getFileForDocId(parentDocumentId);
    final NetworkConnection connection = getNetworkConnection(parentDocumentId);
    try {
        connection.getConnectedClient().changeWorkingDirectory(parent.getPath());
        for (FTPFile file : connection.getConnectedClient().listFiles()) {
            includeFile(result, null, new NetworkFile(parent, file));
        }
    } catch (IOException e) {
        CrashReportingManager.logException(e);
    }
    return result;
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:17,代碼來源:NetworkStorageProvider.java

示例15: testSetuid

import org.apache.commons.net.ftp.FTPFile; //導入依賴的package包/類
@Test
public void testSetuid() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
            "drwsr--r--   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry(
            "drwSr--r--   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:19,代碼來源:UnixFTPEntryParserTest.java


注:本文中的org.apache.commons.net.ftp.FTPFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。