0
我試圖運行的打算在Linux服務器上修改文件權限爲777以下Groovy腳本的Linux SFTP服務器建立連接 -與使用Groovy
@GrabConfig(systemClassLoader = true)
@Grab(group="com.jcraft", module="jsch", version="0.1.46")
import com.jcraft.jsch.*;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelSession;
import java.io.InputStream;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Vector;
java.util.Properties config = new java.util.Properties()
config.put "StrictHostKeyChecking", "no"
JSch ssh = new JSch();
Session session = null;
Session sess = ssh.getSession ("USERNAME", "HOST", 22);
sess.with {
setConfig config
setPassword ("PASSWORD");
connect()
Channel chan = openChannel ("sftp");
chan.connect()
ChannelSftp sftp = (ChannelSftp) chan;
"chmod 777".execute(null, new File("WORKING DIRECTORY\Test_ftpuser_place.txt"))
chan.disconnect()
disconnect()
}
此外,我試着用下面的命令而不是Chmod,但仍然無效。
builder = new AntBuilder()
builder.chmod(dir:"WORKING DIRECTORY", perm:'+rwxrwxrwx', includes:'Test_ftpuser.txt')
並即時得到上運行腳本的前半部分這個錯誤 -
java.io.IOException: Cannot run program "chmod": CreateProcess error=2, The system cannot find the file specified
at java_lang_Runtime$exec$0.call(Unknown Source)
at ConsoleScript45$_run_closure1.doCall(ConsoleScript45:45)
at ConsoleScript45.run(ConsoleScript45:18)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
... 3 more
可能有人請幫我出這一點。
謝謝!