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


Java FTPClient.makeDirectory方法代碼示例

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


在下文中一共展示了FTPClient.makeDirectory方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeRemoteDir

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
protected void makeRemoteDir(FTPClient ftp, String dir)
        throws IOException {
    String workingDirectory = ftp.printWorkingDirectory();
    if (dir.indexOf("/") == 0) {
        ftp.changeWorkingDirectory("/");
    }
    String subdir;
    StringTokenizer st = new StringTokenizer(dir, "/");
    while (st.hasMoreTokens()) {
        subdir = st.nextToken();
        if (!(ftp.changeWorkingDirectory(subdir))) {
            if (!(ftp.makeDirectory(subdir))) {
                int rc = ftp.getReplyCode();
                if (rc != 550 && rc != 553 && rc != 521) {
                    throw new IOException("could not create directory: " + ftp.getReplyString());
                }
            } else {
                ftp.changeWorkingDirectory(subdir);
            }
        }
    }
    if (workingDirectory != null) {
        ftp.changeWorkingDirectory(workingDirectory);
    }
}
 
開發者ID:numsg,項目名稱:spring-boot-seed,代碼行數:26,代碼來源:FtpHelper.java

示例2: mkdirs

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的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 boolean mkdirs(FTPClient client, Path file, FsPermission permission)
    throws IOException {
  boolean created = true;
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  String pathName = absolute.getName();
  if (!exists(client, absolute)) {
    Path parent = absolute.getParent();
    created = (parent == null || mkdirs(client, parent, FsPermission
        .getDirDefault()));
    if (created) {
      String parentDir = parent.toUri().getPath();
      client.changeWorkingDirectory(parentDir);
      created = created && client.makeDirectory(pathName);
    }
  } else if (isFile(client, absolute)) {
    throw new ParentNotDirectoryException(String.format(
        "Can't make directory for path %s since it is a file.", absolute));
  }
  return created;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:FTPFileSystem.java

示例3: uploadDirectory

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * Recursively upload a directory to FTP server with the provided FTP client object.
 *
 * @param sourceDirectoryPath
 * @param targetDirectoryPath
 * @param logPrefix
 * @throws IOException
 */
protected void uploadDirectory(final FTPClient ftpClient, final String sourceDirectoryPath,
                               final String targetDirectoryPath, final String logPrefix) throws IOException {
    log.info(String.format(UPLOAD_DIR, logPrefix, sourceDirectoryPath, targetDirectoryPath));
    final File sourceDirectory = new File(sourceDirectoryPath);
    final File[] files = sourceDirectory.listFiles();
    if (files == null || files.length == 0) {
        log.info(String.format("%sEmpty directory at %s", logPrefix, sourceDirectoryPath));
        return;
    }

    // Make sure target directory exists
    final boolean isTargetDirectoryExist = ftpClient.changeWorkingDirectory(targetDirectoryPath);
    if (!isTargetDirectoryExist) {
        ftpClient.makeDirectory(targetDirectoryPath);
    }

    final String nextLevelPrefix = logPrefix + "..";
    for (File file : files) {
        if (file.isFile()) {
            uploadFile(ftpClient, file.getAbsolutePath(), targetDirectoryPath, nextLevelPrefix);
        } else {
            uploadDirectory(ftpClient, Paths.get(sourceDirectoryPath, file.getName()).toString(),
                    targetDirectoryPath + "/" + file.getName(), nextLevelPrefix);
        }
    }
}
 
開發者ID:Microsoft,項目名稱:azure-maven-plugins,代碼行數:35,代碼來源:FTPUploader.java

示例4: ensureDirectoryExists

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
@Override
public void ensureDirectoryExists(final FlowFile flowFile, final File directoryName) throws IOException {
    if (directoryName.getParent() != null && !directoryName.getParentFile().equals(new File(File.separator))) {
        ensureDirectoryExists(flowFile, directoryName.getParentFile());
    }

    final String remoteDirectory = directoryName.getAbsolutePath().replace("\\", "/").replaceAll("^.\\:", "");
    final FTPClient client = getClient(flowFile);
    final boolean cdSuccessful = setWorkingDirectory(remoteDirectory);

    if (!cdSuccessful) {
        logger.debug("Remote Directory {} does not exist; creating it", new Object[] {remoteDirectory});
        if (client.makeDirectory(remoteDirectory)) {
            logger.debug("Created {}", new Object[] {remoteDirectory});
        } else {
            throw new IOException("Failed to create remote directory " + remoteDirectory);
        }
    }
}
 
開發者ID:clickha,項目名稱:nifi-tools,代碼行數:20,代碼來源:FTPTransferV2.java

示例5: MKDAndCWD

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
private boolean MKDAndCWD(FTPClient ftp, String remoteDir) throws IOException {
    // 切分出所有子文件夾,按順序
    String[] dirs = remoteDir.split("/");
    // 遍曆文件夾
    for (String subDir : dirs) {
        // 文件夾字符串非空
        if (!subDir.isEmpty()) {
            // 切換工作目錄
            if (!ftp.changeWorkingDirectory(subDir)) {
                // 若目錄不存在則先創建
                if (!ftp.makeDirectory(subDir)) {
                    return false;
                }
                // 切換工作目錄
                if (!ftp.changeWorkingDirectory(subDir)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
開發者ID:wyp0596,項目名稱:elegant-springboot,代碼行數:23,代碼來源:MyFtpClient.java

示例6: uploadFileToWebApp

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * Uploads a file to an Azure web app.
 * @param profile the publishing profile for the web app.
 * @param fileName the name of the file on server
 * @param file the local file
 */
public static void uploadFileToWebApp(PublishingProfile profile, String fileName, InputStream file) {
    FTPClient ftpClient = new FTPClient();
    String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);
    String server = ftpUrlSegments[0];
    String path = "./site/wwwroot/webapps";
    if (fileName.contains("/")) {
        int lastslash = fileName.lastIndexOf('/');
        path = path + "/" + fileName.substring(0, lastslash);
        fileName = fileName.substring(lastslash + 1);
    }
    try {
        ftpClient.connect(server);
        ftpClient.login(profile.ftpUsername(), profile.ftpPassword());
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        for (String segment : path.split("/")) {
            if (!ftpClient.changeWorkingDirectory(segment)) {
                ftpClient.makeDirectory(segment);
                ftpClient.changeWorkingDirectory(segment);
            }
        }
        ftpClient.storeFile(fileName, file);
        ftpClient.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Azure-Samples,項目名稱:acr-java-manage-azure-container-registry,代碼行數:33,代碼來源:Utils.java

示例7: uploadFileToFunctionApp

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * Uploads a file to an Azure function app.
 * @param profile the publishing profile for the web app.
 * @param fileName the name of the file on server
 * @param file the local file
 */
public static void uploadFileToFunctionApp(PublishingProfile profile, String fileName, InputStream file) {
    FTPClient ftpClient = new FTPClient();
    String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);
    String server = ftpUrlSegments[0];
    String path = "site/wwwroot";
    if (fileName.contains("/")) {
        int lastslash = fileName.lastIndexOf('/');
        path = path + "/" + fileName.substring(0, lastslash);
        fileName = fileName.substring(lastslash + 1);
    }
    try {
        ftpClient.connect(server);
        ftpClient.login(profile.ftpUsername(), profile.ftpPassword());
        ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
        for (String segment : path.split("/")) {
            if (!ftpClient.changeWorkingDirectory(segment)) {
                ftpClient.makeDirectory(segment);
                ftpClient.changeWorkingDirectory(segment);
            }
        }
        ftpClient.storeFile(fileName, file);
        ftpClient.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Azure-Samples,項目名稱:acr-java-manage-azure-container-registry,代碼行數:33,代碼來源:Utils.java

示例8: mkDir

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
* 循環創建目錄,並且創建完目錄後,設置工作目錄為當前創建的目錄下
*/
public static boolean mkDir(String ftpPath,FTPClient ftp2) {
 if (!ftp2.isConnected()) {
  return false;
 }
 try {
  // 將路徑中的斜杠統一
  char[] chars = ftpPath.toCharArray();
  StringBuffer sbStr = new StringBuffer(256);
  for (int i = 0; i < chars.length; i++) {
   if ('\\' == chars[i]) {
   	sbStr.append('/');
   }else{
   	sbStr.append(chars[i]);
   }
  }
  ftpPath = sbStr.toString();
  //System.out.println("ftpPath" + ftpPath);
  if (ftpPath.indexOf('/') == -1) {
   // 隻有一層目錄
   ftp2.makeDirectory(new String(ftpPath.getBytes(),"iso-8859-1"));
   ftp2.changeWorkingDirectory(new String(ftpPath.getBytes(),"iso-8859-1"));
  } else {
   // 多層目錄循環創建
   String[] paths = ftpPath.split("/");
   // String pathTemp = "";
   for (int i = 0; i < paths.length; i++) {
   	ftp2.makeDirectory(new String(paths[i].getBytes(),"iso-8859-1"));
   	ftp2.changeWorkingDirectory(new String(paths[i].getBytes(), "iso-8859-1"));
   }
  }
  return true;
 } catch (Exception e) {
  e.printStackTrace();
  return false;
 }
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:40,代碼來源:FtpClient.java

示例9: createDirecroty

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * 遞歸創建遠程服務器目錄
 *
 * @param remote    遠程服務器文件絕對路徑
 * @param ftpClient FTPClient對象
 * @return 目錄創建是否成功
 * @throws IOException
 */
public UploadStatus createDirecroty(String remote, FTPClient ftpClient)
        throws IOException {
    UploadStatus status = UploadStatus.Create_Directory_Success;
    String directory = remote.substring(0, remote.lastIndexOf("/") + 1);
    if (!directory.equalsIgnoreCase("/")
            && !ftpClient.changeWorkingDirectory(new String(directory
            .getBytes(DEAFULT_REMOTE_CHARSET), DEAFULT_LOCAL_CHARSET))) {
        // 如果遠程目錄不存在,則遞歸創建遠程服務器目錄
        int start;
        int end;
        if (directory.startsWith("/")) {
            start = 1;
        } else {
            start = 0;
        }
        end = directory.indexOf("/", start);
        while (true) {
            String subDirectory = new String(remote.substring(start, end)
                    .getBytes(DEAFULT_REMOTE_CHARSET), DEAFULT_LOCAL_CHARSET);
            if (!ftpClient.changeWorkingDirectory(subDirectory)) {
                if (ftpClient.makeDirectory(subDirectory)) {
                    ftpClient.changeWorkingDirectory(subDirectory);
                } else {
                    //System.out.println("創建目錄失敗")
                    return UploadStatus.Create_Directory_Fail;
                }
            }
            start = end + 1;
            end = directory.indexOf("/", start);
            // 檢查所有目錄是否創建完畢
            if (end <= start) {
                break;
            }
        }
    }
    return status;
}
 
開發者ID:numsg,項目名稱:spring-boot-seed,代碼行數:46,代碼來源:FtpHelper.java

示例10: testPathNames

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * Test of obscure path names in the FTP server
 * 
 * RFC959 states that paths are constructed thus...
 * <string> ::= <char> | <char><string>
 * <pathname> ::= <string>
 * <char> ::= any of the 128 ASCII characters except <CR> and <LF>
 *       
 *  So we need to check how high characters and problematic are encoded     
 */
public void testPathNames() throws Exception
{
    
    logger.debug("Start testPathNames");
    
    FTPClient ftp = connectClient();

    String PATH1="testPathNames";
    
    try
    {
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
    
        boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN);
        assertTrue("admin login successful", login);
                      
        reply = ftp.cwd("/Alfresco/User*Homes");
        assertTrue(FTPReply.isPositiveCompletion(reply));
                    
        // Delete the root directory in case it was left over from a previous test run
        try
        {
            ftp.removeDirectory(PATH1);
        }
        catch (IOException e)
        {
            // ignore this error
        }
        
        // make root directory for this test
        boolean success = ftp.makeDirectory(PATH1);
        assertTrue("unable to make directory:" + PATH1, success);
        
        success = ftp.changeWorkingDirectory(PATH1);
        assertTrue("unable to change to working directory:" + PATH1, success);
        
        assertTrue("with a space", ftp.makeDirectory("test space"));
        assertTrue("with exclamation", ftp.makeDirectory("space!"));
        assertTrue("with dollar", ftp.makeDirectory("space$"));
        assertTrue("with brackets", ftp.makeDirectory("space()"));
        assertTrue("with hash curley  brackets", ftp.makeDirectory("space{}"));


        //Pound sign U+00A3
        //Yen Sign U+00A5
        //Capital Omega U+03A9

        assertTrue("with pound sign", ftp.makeDirectory("pound \u00A3.world"));
        assertTrue("with yen sign", ftp.makeDirectory("yen \u00A5.world"));
        
        // Test steps that do not work
        // assertTrue("with omega", ftp.makeDirectory("omega \u03A9.world"));
        // assertTrue("with obscure ASCII chars", ftp.makeDirectory("?/.,<>"));    
    } 
    finally
    {
        // clean up tree if left over from previous run

        ftp.disconnect();
    }    


}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:79,代碼來源:FTPServerTest.java

示例11: testRenameCase

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類
/**
 * Test of rename case ALF-20584
 * 
  
 */
public void testRenameCase() throws Exception
{
    
    logger.debug("Start testRenameCase");
    
    FTPClient ftp = connectClient();

    String PATH1="testRenameCase";
    
    try
    {
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            fail("FTP server refused connection.");
        }
    
        boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN);
        assertTrue("admin login successful", login);
                      
        reply = ftp.cwd("/Alfresco/User*Homes");
        assertTrue(FTPReply.isPositiveCompletion(reply));
                    
        // Delete the root directory in case it was left over from a previous test run
        try
        {
            ftp.removeDirectory(PATH1);
        }
        catch (IOException e)
        {
            // ignore this error
        }
        
        // make root directory for this test
        boolean success = ftp.makeDirectory(PATH1);
        assertTrue("unable to make directory:" + PATH1, success);
        
        ftp.cwd(PATH1);
        
        String FILE1_CONTENT_2="That's how it is says Pooh!";
        ftp.storeFile("FileA.txt" , new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8")));
        
        assertTrue("unable to rename", ftp.rename("FileA.txt", "FILEA.TXT"));
    
    } 
    finally
    {
        // clean up tree if left over from previous run

        ftp.disconnect();
    }    


}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:61,代碼來源:FTPServerTest.java


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