当前位置: 首页>>代码示例>>Java>>正文


Java FTPClient.completePendingCommand方法代码示例

本文整理汇总了Java中org.apache.commons.net.ftp.FTPClient.completePendingCommand方法的典型用法代码示例。如果您正苦于以下问题:Java FTPClient.completePendingCommand方法的具体用法?Java FTPClient.completePendingCommand怎么用?Java FTPClient.completePendingCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.ftp.FTPClient的用法示例。


在下文中一共展示了FTPClient.completePendingCommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadFile

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
/**  
 * �ϴ��ļ���������,���ϴ��Ͷϵ�����  
 * @param remoteFile Զ���ļ��������ϴ�֮ǰ�Ѿ�������������Ŀ¼���˸ı�  
 * @param localFile �����ļ� File���������·��  
 * @param processStep ��Ҫ��ʾ�Ĵ�����Ȳ���ֵ  
 * @param ftpClient FTPClient ����  
 * @return  
 * @throws IOException  
 */  
public UploadStatus uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{   
    UploadStatus status;   
    //��ʾ���ȵ��ϴ�   
    long step = localFile.length() / 100;   
    long process = 0;   
    long localreadbytes = 0L;   
    RandomAccessFile raf = new RandomAccessFile(localFile,"r");   
    OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"iso-8859-1")); 
    //�ϵ�����   
    if(remoteSize>0){   
        ftpClient.setRestartOffset(remoteSize);   
        process = remoteSize /step;   
        raf.seek(remoteSize);   
        localreadbytes = remoteSize;   
    }   
    byte[] bytes = new byte[1024];   
    int c;   
    while((c = raf.read(bytes))!= -1){   
        out.write(bytes,0,c);   
        localreadbytes+=c;   
        if(localreadbytes / step != process){   
            process = localreadbytes / step;   
            System.out.println("�ϴ�����:" + process);   
            //TODO �㱨�ϴ�״̬   
        }   
    }   
    out.flush();   
    raf.close();   
    out.close();   
    boolean result =ftpClient.completePendingCommand();   
    if(remoteSize > 0){   
        status = result?UploadStatus.Upload_From_Break_Success:UploadStatus.Upload_From_Break_Failed;   
    }else {   
        status = result?UploadStatus.Upload_New_File_Success:UploadStatus.Upload_New_File_Failed;   
    }   
    return status;   
}
 
开发者ID:cai784921129,项目名称:FTP,代码行数:47,代码来源:ContinueFTP.java

示例2: create

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
/**
 * A stream obtained via this call must be closed before using other APIs of
 * this class or else the invocation will block.
 */
@Override
public FSDataOutputStream create(Path file, FsPermission permission,
    boolean overwrite, int bufferSize, short replication, long blockSize,
    Progressable progress) throws IOException {
  final FTPClient client = connect();
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  FileStatus status;
  try {
    status = getFileStatus(client, file);
  } catch (FileNotFoundException fnfe) {
    status = null;
  }
  if (status != null) {
    if (overwrite && !status.isDirectory()) {
      delete(client, file, false);
    } else {
      disconnect(client);
      throw new FileAlreadyExistsException("File already exists: " + file);
    }
  }
  
  Path parent = absolute.getParent();
  if (parent == null || !mkdirs(client, parent, FsPermission.getDirDefault())) {
    parent = (parent == null) ? new Path("/") : parent;
    disconnect(client);
    throw new IOException("create(): Mkdirs failed to create: " + parent);
  }
  client.allocate(bufferSize);
  // 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();
      if (!client.isConnected()) {
        throw new FTPException("Client not connected");
      }
      boolean cmdCompleted = client.completePendingCommand();
      disconnect(client);
      if (!cmdCompleted) {
        throw new FTPException("Could not complete transfer, Reply Code - "
            + client.getReplyCode());
      }
    }
  };
  if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {
    // The ftpClient is an inconsistent state. Must close the stream
    // which in turn will logout and disconnect from FTP server
    fos.close();
    throw new IOException("Unable to create file: " + file + ", Aborting");
  }
  return fos;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:64,代码来源:FTPFileSystem.java

示例3: flush

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public void flush() throws IOException {
    final FTPClient client = getClient(null);
    client.completePendingCommand();
}
 
开发者ID:clickha,项目名称:nifi-tools,代码行数:6,代码来源:FTPTransferV2.java

示例4: getMessage

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public String getMessage() throws IOException {
	String message = null;
	try 
	{
		FTPClient ftpClient = new FTPClient();
		ftpClient.connect(server, port);
		ftpClient.login(user, password);
		ftpClient.enterLocalPassiveMode();
		ftpClient.setFileType(2);

		String remoteFile1 = "/"+file;
		InputStream inputStream = ftpClient.retrieveFileStream(remoteFile1);
		message = StreamUtility.readStream(inputStream, "iso-8859-1");
	    Boolean success = ftpClient.completePendingCommand();
	    
		if (success) {
			System.out.println("File has been downloaded successfully.");
		}
		
		inputStream.close();
	}
	catch (IOException e)
	{
		/* SendMail mail = new SendMail();
	      try
	      {
	        mail.postMail(this.properties.getProperty("mail"), "TMC-Fehler", 
	          e.getStackTrace().toString(), "[email protected]", this.properties
	          .getProperty("smtpHost"), this.properties
	          .getProperty("smtpUser"), this.properties
	          .getProperty("smtpPort"));
	      }
	      catch (MessagingException e1)
	      {
	        e1.printStackTrace();
	      }
	      this.logger.debug("Error with FTP connection " + 
	        e.getLocalizedMessage(), e);
	      throw new DownloadException(
	        "Error while downloading file from FTP " + 
	        e.getLocalizedMessage(), e);
		 */
	}

	return message;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:48,代码来源:FtpDataSource.java


注:本文中的org.apache.commons.net.ftp.FTPClient.completePendingCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。