1
リモートファイルに文字列コンテンツを配置する必要があります。Javaを使用してリモートマシンのファイルに文字列コンテンツを転送する
理想的には、私はローカルでファイルを作成してから、そのファイルをリモートマシンに転送していました。
以下は、ファイルをリモートにコピーするために使用したコードスニペットです。
ChannelSftp sftpChannel = (ChannelSftp) channel;
File file = new File(filePathWithName);//To read the file in local machine
try {
sftpChannel.cd(location);//Remote location
//Transferring the file to RemoteLocation.
sftpChannel.put(new FileInputStream(file), file.getName());//.(Here I don't want read a file.) //Instead I want copy a content which is in string variable, something like below two lines, to the remote location.
String content = "abcdefg";
sftpChannel.put(content,"someFileName")
} catch (SftpException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
sftpChannel.exit();
リモートマシンで同じことを作成するために、ローカルでファイルを読み込む克服するための任意の参照やドキュメントがあります。
-Thankあなた