In Unix, how do I set the directory permissions with JSCH? I am looking to do drwxrwxrwx. Filezilla says the integer for that is 775 but JSCH is not setting the permission
here is a short and a full example of how to can easyly use Jsch to change a chmod by using the usual way to decrib a CHMOD permission
========================================================= short answer : int chmodInt = Integer.parseInt(chmod, 8); channel.chmod(chmodInt, fileLinux);
========================================================= Full Example :
package example;
import java.io.IOException;
import java.util.Date;
import main.services.ServiceSSH;
import org.junit.Test;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
public class ExampleChmod {
@Test
public void testchmod() throws JSchException, SftpException, IOException {
Session session = ServiceSSH.getSession(); // Use your own session Factory
Date dateStart = new Date();
chmod("/home/user/launcher.sh", "777", session);
Date dateEnd = new Date();
session.disconnect();
System.out.println(dateEnd.getTime() - dateStart.getTime() + "ms");
}
public static void chmod(String fileLinux, String chmod, Session session) throws JSchException, SftpException {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
chmod(fileLinux, chmod, channel);
channel.disconnect();
}
private static void chmod(String fileLinux, String chmod, ChannelSftp channel) throws SftpException {
int chmodInt = Integer.parseInt(chmod, 8);
channel.chmod(chmodInt, fileLinux);
}
}