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


Java FTPFile.getName方法代碼示例

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


在下文中一共展示了FTPFile.getName方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例3: downloadFolderFiles

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
/**
 * 從遠程服務器目錄下載文件到本地服務器目錄中
 *
 * @param ftp          ftp對象
 * @param localdir     本地文件夾路徑
 * @param remotedir    遠程文件夾路徑
 * @param localTmpFile 本地下載文件名記錄
 * @return
 * @throws IOException
 */
private Collection<String> downloadFolderFiles(FTPClient ftp, final String localdir, final String remotedir, final String localTmpFile) throws IOException {
    //切換到下載目錄的中
    ftp.changeWorkingDirectory(remotedir);
    //獲取目錄中所有的文件信息
    FTPFile[] ftpfiles = ftp.listFiles();
    Collection<String> fileNamesCol = new ArrayList<>();
    //判斷文件目錄是否為空
    if (!ArrayUtils.isEmpty(ftpfiles)) {
        for (FTPFile ftpfile : ftpfiles) {
            String remoteFilePath = ftpfile.getName();
            String localFilePath = localdir + separator + ftpfile.getName();
            //System.out.println("remoteFilePath ="+remoteFilePath +" localFilePath="+localFilePath)
            //單個文件下載狀態
            DownloadStatus downStatus = FtpHelper.getInstance().download(ftp, remoteFilePath, localFilePath);
            if (downStatus == DownloadStatus.Download_New_Success) {
                //臨時目錄中添加記錄信息
                fileNamesCol.add(remoteFilePath);
            }
        }
    }
    if (!fileNamesCol.isEmpty() && !StringUtils.isEmpty(localTmpFile)) {
        FileOperateUtils.writeLinesToFile(fileNamesCol, localTmpFile, false);
    }
    return fileNamesCol;
}
 
開發者ID:numsg,項目名稱:spring-boot-seed,代碼行數:36,代碼來源:FTPClientImpl.java

示例4: downloadNewApkFile

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
private void downloadNewApkFile(FTPFile file) {
    _logger.Debug(String.format(Locale.GERMAN, "Downloading new file: %s", file));

    String remoteFilePath = Constants.NAS_PUBLIC + "Shared Applications/" + file.getName();
    File downloadFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + file.getName());

    new Thread(() -> {
        if (DownloadSingleFile(Constants.NAS_1, Constants.USER, Constants.PASSPHRASE, remoteFilePath, downloadFile)) {
            _broadCastController.SendStringBroadcast(
                    Broadcasts.FTP_FILE_UPDATE_DOWNLOAD_FINISHED,
                    Bundles.FILE_PATH,
                    downloadFile.getAbsolutePath());
        } else {
            _logger.Error("Download failed!");
        }
    }).start();
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-MediaServer,代碼行數:18,代碼來源:MediaMirrorFTPController.java

示例5: downloadFile

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
public static boolean downloadFile(String url, int port, String username, String password,
                                   String remotePath, String fileName, String localPath) {
    boolean success = false;
    FTPClient ftp = new FTPClient();
    try {
        int reply;
        ftp.connect(url, port);
        ftp.login(username, password);
        reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            return success;
        }
        ftp.changeWorkingDirectory(remotePath);
        FTPFile[] fs = ftp.listFiles();
        System.out.println(fs.length);
        for (FTPFile ff : fs) {
            System.out.println(ff.getName());
            if (ff.getName().equals(fileName)) {
                File localFile = new File(localPath + "/" + ff.getName());
                OutputStream is = new FileOutputStream(localFile);
                ftp.retrieveFile(ff.getName(), is);
                is.close();
            }
        }
        ftp.logout();
        success = true;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException ioe) {
            }
        }
    }
    return success;
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:40,代碼來源:FtpUtils.java

示例6: newFileInfo

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
private FileInfo newFileInfo(final FTPFile file, String path) {
    if (file == null) {
        return null;
    }
    final File newFullPath = new File(path, file.getName());
    final String newFullForwardPath = newFullPath.getPath().replace("\\", "/");
    StringBuilder perms = new StringBuilder();
    perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-");
    perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-");
    perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-");
    perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-");
    perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-");
    perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-");
    perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-");
    perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-");
    perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-");

    FileInfo.Builder builder = new FileInfo.Builder()
        .filename(file.getName())
        .fullPathFileName(newFullForwardPath)
        .directory(file.isDirectory())
        .size(file.getSize())
        .lastModifiedTime(file.getTimestamp().getTimeInMillis())
        .permissions(perms.toString())
        .owner(file.getUser())
        .group(file.getGroup());
    return builder.build();
}
 
開發者ID:clickha,項目名稱:nifi-tools,代碼行數:29,代碼來源:FTPTransferV2.java

示例7: getFileDisplayText

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
private String getFileDisplayText(FTPClient client, FTPFile file) throws Exception {

        String name = file.getName() + " | " +
                ft.format(file.getTimestamp().getTime()) + " | " +
                fileSyncStatus(file, client.printWorkingDirectory() + File.separator + file.getName());

        return name;

    }
 
開發者ID:Ross-Byrne,項目名稱:ftpSync,代碼行數:10,代碼來源:MainController.java

示例8: buildFileTree

import org.apache.commons.net.ftp.FTPFile; //導入方法依賴的package包/類
private void buildFileTree(TreeItem treeNode, FTPClient client) throws Exception {

        // display the files
        FTPFile[] files = client.listFiles("", FTPFile::isFile);

        for (FTPFile file : files) {

            if(!file.getName().startsWith(".")) {

                System.out.println("File: " + file.getName());

                // add file to file tree
                treeNode.getChildren().add(new TreeItem<>(getFileDisplayText(client, file)));

            } // if

        } // for

        // get the directories
        FTPFile[] directories = client.listDirectories();

        for (FTPFile dir : directories) {

            if(!dir.getName().startsWith(".")) {

                // change working directory to detected directory
                client.changeWorkingDirectory(dir.getName());

                // save working dir
                String pwd = client.printWorkingDirectory();

                // create treeItem to represent new Directory
                TreeItem newDir = new TreeItem<>(dir.getName(), new ImageView(dirIcon));
                newDir.setExpanded(false);

                // add directory to file tree
                treeNode.getChildren().add(newDir);

                Platform.runLater(() -> logTA.appendText("\nDiscovering Files in: " + pwd));
                System.out.println("Discovering Files in: " + pwd);

                // recursively call method to add files and directories to new directory
                buildFileTree(newDir, client);

                // go back to parent directory, once finished in this directory
                client.changeToParentDirectory();

            } // if

        } // for

    }
 
開發者ID:Ross-Byrne,項目名稱:ftpSync,代碼行數:53,代碼來源:MainController.java


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