Search code examples
cygwinsftpfile-transferjsch

sftp JSch transfer file to remote cygwin


I am trying copy files from local windows machine to remote windows machine using sftp JSch. Remote machine has cygwin, but file is not getting transferred. While doing, it is not throwing any error.

I tried with different destination path format like /cygdrive/d/ and also d://.

String destination = "/cygdrive/d/Test1";
String source = "D:\\Test";

List<String> files = NFileUtils.listFiles(source);
for (String f : files) {
    String fileName = NFileUtils.getFilename(f);
    try {
        sftp.put(f, destination + "\\" + fileName);
    } catch (Exception e) {
        System.out.println(e);
    }
}

Solution

  • sftp.put(f, destination + "\\" + fileName);
    

    SFTP uses a file-naming model in which "/" is the directory separator character. Try using "/" as the path separator instead of "\":

    sftp.put(f, destination + "/" + fileName);
    

    If fileName contains any "\" characters, you'll need to change them as well.