I tried to solve your problem, and I found myself in the same situation, the created file remains empty.
However, I think I found the cause of the problem.
Here is an excerpt from ch.ethz.ssh2.SFTPv3Client.write () of the ganymed API method
public void write(SFTPv3FileHandle handle, long fileOffset, byte[] src, int srcoff, int len) throws IOException { checkHandleValidAndOpen(handle); if (len < 0) while (len > 0) {
You see, when you send data for writing, len is> 0, and due to the fictitious condition, the method returns immediately, and it never enters the while loop (which actually writes something to the file).
I assume that it was immediately after "if (len & lt 0)" earlier, but someone removed it and left us a useless part of the code ...
Update:
Go get the latest version (the example above used assembly 210). I had no problems building 250 and 251.
Here is my code, and it writes the new file correctly on my ssh server.
you will need bulletproof :)
public static void main(String[] args) throws Exception { Connection conn = new Connection(hostname); conn.connect(); boolean isAuthenticated = conn.authenticateWithPassword(username, password); if (isAuthenticated == false) throw new IOException("Authentication failed."); SFTPv3Client client = new SFTPv3Client(conn); File tmpFile = File.createTempFile("teststackoverflow", "dat"); FileWriter fw = new FileWriter(tmpFile); fw.write("this is a test"); fw.flush(); fw.close(); SFTPv3FileHandle handle = client.createFile(tmpFile.getName()); FileInputStream fis = new FileInputStream(tmpFile); byte[] buffer = new byte[1024]; int i=0; long offset=0; while ((i = fis.read(buffer)) != -1) { client.write(handle,offset,buffer,0,i); offset+= i; } client.closeFile(handle); if (handle.isClosed()) System.out.println("closed");; client.close(); }