我试图构建一个小代码,希望在其中创建一些字符串并将该字符串传输到位于远程服务器中的文件(应该在运行时创建)。在我的例子中,远程服务器是Linux。
有人能帮我一下吗?我使用的是JSCH和ChannelSftp,但无法执行此操作。下面是我的代码:JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER, MachineIP, SFTPPORT);
String str = "Hello";
session.setPassword(SFTPPASS);
System.out.println(SFTPPASS);
java.util.Properties config = new java.util.Properties();
System.out.println("Config done");
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Config set");
session.connect();
System.out.println("Session connected");
channel = session.openChannel("sftp");
channel.connect();
System.out.println("Connection Opened\n");
channelSftp = (ChannelSftp) channel;
channelSftp.cd(SFTPWORKINGDIR);
File f=new File("Test.txt");
//unable to do anything beyond this.
抱歉,如果你觉得这很愚蠢,但我对此很陌生。