Package org.apache.commons.net.ftp

Examples of org.apache.commons.net.ftp.FTPClient.changeWorkingDirectory()


                path = path.substring(1);
            }

            //Checking if it is a file or a directory
            boolean isFile = this.isFile(endpoint, client);
            if (!isFile && !client.changeWorkingDirectory(path))
            {
                throw new IOException(MessageFormat.format("Failed to change working directory to {0}. Ftp error: {1}",
                                                           path, client.getReplyCode()));
            }
            else if (isFile)
View Full Code Here


            {
                // Changing the working directory to the parent folder, it should be better if
                // the ftpClient API would provide a way to retrieve the parent folder
                FTPFile[] listFiles = client.listFiles(path);
                String directory = path.replaceAll(listFiles[0].getName(), "");
                client.changeWorkingDirectory(directory);
            }
        }
        return client;
    }
View Full Code Here

    // file
    // on the server by opening up an InputStream. As a side effect the working
    // directory on the server is changed to the parent directory of the file.
    // The FTP client connection is closed when close() is called on the
    // FSDataInputStream.
    client.changeWorkingDirectory(parent.toUri().getPath());
    InputStream is = client.retrieveFileStream(file.getName());
    FSDataInputStream fis = new FSDataInputStream(new FTPInputStream(is,
        client, statistics));
    if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {
      // The ftpClient is an inconsistent state. Must close the stream
View Full Code Here

    // Change to parent directory on the server. Only then can we write to the
    // file on the server by opening up an OutputStream. As a side effect the
    // working directory on the server is changed to the parent directory of the
    // file. The FTP client connection is closed when close() is called on the
    // FSDataOutputStream.
    client.changeWorkingDirectory(parent.toUri().getPath());
    FSDataOutputStream fos = new FSDataOutputStream(client.storeFileStream(file
        .getName()), statistics) {
      @Override
      public void close() throws IOException {
        super.close();
View Full Code Here

    workingPath = path;
    pathStack.add(workingPath);
    try {
      ftpClient.connect(ftp.getFtpIp(), Integer.valueOf(port));//连接FTP服务器
      ftpClient.login(username, password);//登录
      ftpClient.changeWorkingDirectory(path);
      File file = new File(sourcePath);
      if (file.exists() && file.isDirectory()) {
        File sourceFile[] = file.listFiles();
        for (File subFile : sourceFile) {
          if (subFile.isDirectory()) {//是目录的话
View Full Code Here

    // file
    // on the server by opening up an InputStream. As a side effect the working
    // directory on the server is changed to the parent directory of the file.
    // The FTP client connection is closed when close() is called on the
    // FSDataInputStream.
    client.changeWorkingDirectory(parent.toUri().getPath());
    InputStream is = client.retrieveFileStream(file.getName());
    FSDataInputStream fis = new FSDataInputStream(new FTPInputStream(is,
        client, statistics));
    if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {
      // The ftpClient is an inconsistent state. Must close the stream
View Full Code Here

    // Change to parent directory on the server. Only then can we write to the
    // file on the server by opening up an OutputStream. As a side effect the
    // working directory on the server is changed to the parent directory of the
    // file. The FTP client connection is closed when close() is called on the
    // FSDataOutputStream.
    client.changeWorkingDirectory(parent.toUri().getPath());
    FSDataOutputStream fos = new FSDataOutputStream(client.storeFileStream(file
        .getName()), statistics) {
      @Override
      public void close() throws IOException {
        super.close();
View Full Code Here

      fail("Unexpected exception: " + ex.getMessage());
    }

    try (final Tx tx = app.tx()) {

      ftp.changeWorkingDirectory("/" + name2);

      String[] fileNames = ftp.listNames();

      assertNotNull(fileNames);
      assertEquals(1, fileNames.length);
View Full Code Here

    }

    String[] fileNames = null;
    try (final Tx tx = app.tx()) {

      ftp.changeWorkingDirectory("/" + name2);

      fileNames = ftp.listNames();

      assertNotNull(fileNames);
      assertEquals(1, fileNames.length);
View Full Code Here

      fail("Unexpected exception: " + ex.getMessage());
    }

    try (final Tx tx = app.tx()) {

      ftp.changeWorkingDirectory("/");
      tx.success();

    } catch (Exception ex) {
      ex.printStackTrace();
      fail("Unexpected exception: " + ex.getMessage());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.