commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kenji (JIRA)" <>
Subject [jira] [Created] (VFS-647) calling findFiles() causes copyFrom() to fail with a partially downloaded file.
Date Wed, 18 Oct 2017 17:57:03 GMT
Kenji created VFS-647:

             Summary: calling findFiles() causes copyFrom() to fail with a partially downloaded
                 Key: VFS-647
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 2.2, 2.0
         Environment: Windows 7 and Linux Red Hat.
            Reporter: Kenji
            Priority: Minor

When using FileObject.copyFrom(remote, new AllFileSelector()) to download file from remote
to local directory. If SftpFileObject.findFiles(new FileDepthSelector(1,1)) is called and
finished, then the copyFrom will get interrupted with error pipe closed.

Below are test codes and stack trace error. In real scenario, this all happens within 1 or
2 second time frame. However, with test scenario, I wasn't able to reproduce it easily therefore
I had to choose a file that takes around 10 seconds to download and have Thread.sleep(5000)
after findFiles() call. Only tested jsch-0.1.52, jsch-0.1.54, commons-vfs2-2.0 and commons-vfs2-2.2.

public class FtpClient {
	public static void main(String[] args) {
		if (args.length < 5) {
			throw new RuntimeException("args: host user pass local remote");
		String hostname = args[0];
		String username = args[1];
		String password = args[2];
		int port = 22;
		String local = args[3];
		String remote = args[4];
		final String remoteDir = remote.substring(0, Math.max(0, remote.lastIndexOf("/")));

		Thread t0 = new Thread() {
			public void run() {
				try (Ftp ftp = new Ftp(hostname, port)) {
					ftp.login(username, password);
					System.out.println("findFiles() completed.");
				} catch (Exception e) {

		Thread ti = new Thread() {
			public void run() {
				try (Ftp ftp = new Ftp(hostname, port)) {
					ftp.login(username, password);, remote);
				} catch (Exception e) {



public class Ftp implements AutoCloseable {

	private int timeout = 0;
	private StaticUserAuthenticator userAuth;
	private FileSystemOptions fileSysOpts;
	private FileObject scr = null;
	private FileSystemManager fsm = null;
	private String hostName;
	private int port = 0;

	public Ftp(String remoteHost, int controlPort) throws FileSystemException {
		hostName = remoteHost;
		port = controlPort;
		fsm = VFS.getManager();

	//login into a server with a valid account
	public void login(String user, String password) throws IOException {
		userAuth = new StaticUserAuthenticator(null, user, password); 
		fileSysOpts = new FileSystemOptions();
		DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fileSysOpts, userAuth);

		SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fileSysOpts, "no");
		SftpFileSystemConfigBuilder.getInstance().setTimeout(fileSysOpts, timeout);
		SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fileSysOpts, false);
		scr = (FileObject)fsm.resolveFile("sftp://" + hostName, fileSysOpts);
		System.out.println("login successfully.");

	public void list(String dirName) throws Exception {
		SftpFileObject RemoteFo = (SftpFileObject)fsm.resolveFile("sftp://" + hostName + dirName,
		FileObject[] afo = RemoteFo.findFiles(new FileDepthSelector(1,1));		
		Thread.sleep(5000); //key. this must be here (or some other processing that takes time)
for error to reproduce consistently.

	public void download(String localPath, String remoteFile) throws FileSystemException {
		SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fileSysOpts, "no");
		SftpFileObject RemoteFo = (SftpFileObject)fsm.resolveFile("sftp://" + hostName + remoteFile
		scr = fsm.resolveFile("file:" + localPath);
		scr.copyFrom(RemoteFo, new AllFileSelector());
	public void close() {
			FileSystem fs = null;
				fs = this.scr.getFileSystem();
		}catch(Exception e){
			System.out.println("unable to release ftp connection.");


Oct 18, 2017 12:42:51 PM org.apache.commons.vfs2.VfsLog info
INFO: Using "C:\Users\kenji\AppData\Local\Temp\vfs_cache" as temporary files stor
login successfully.
login successfully.
findFiles() completed.
org.apache.commons.vfs2.FileSystemException: Could not copy "sftp://hostname/path/to/file/FILE1"
to "file:///C:/test/ftp/FILE1".
        at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(Abstract
        at FtpClient$
Caused by: org.apache.commons.vfs2.FileSystemException: Could not close the inpu
t stream for file "sftp://hostname/path/to/file/FILE1".
        at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentInputS
        at org.apache.commons.vfs2.FileUtil.writeContent(
        at org.apache.commons.vfs2.FileUtil.copyContent(
        at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(Abstract
        ... 2 more
Caused by: Pipe closed
        at com.jcraft.jsch.ChannelSftp.fill(
        at com.jcraft.jsch.ChannelSftp.header(
        at com.jcraft.jsch.ChannelSftp.access$500(
        at com.jcraft.jsch.ChannelSftp$RequestQueue.cancel(
        at com.jcraft.jsch.ChannelSftp$2.close(
        at org.apache.commons.vfs2.util.MonitorInputStream.close(MonitorInputStr
        at org.apache.commons.vfs2.util.MonitorInputStream.close(MonitorInputStr
        at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentInputS
        ... 5 more

This message was sent by Atlassian JIRA

View raw message