i need place string content in remote file.
ideally, used create file in local , transfer file remote machine.
below code snippet used, copy file remote.
channelsftp sftpchannel = (channelsftp) channel; file file = new file(filepathwithname);//to read file in local machine try { sftpchannel.cd(location);//remote location //transferring file remotelocation. sftpchannel.put(new fileinputstream(file), file.getname());//.(here don't want read file.) //instead want copy content in string variable, below 2 lines, remote location. string content = "abcdefg"; sftpchannel.put(content,"somefilename") } catch (sftpexception e) { e.printstacktrace(); } catch (filenotfoundexception e) { e.printstacktrace(); } sftpchannel.exit();
is there reference or documentation overcome reading file in local create same in remote machine.
-thank
if understand problem correctly, you'd able copy string data remote machine without reading file locally. if @ javadoc, put
accepts inputstream
. do:
inputstream stream = new bytearrayinputstream(content.getbytes()); sftpchannel.put(stream, "name.txt");
note can put(string dst)
can write outputstream
returned. didn't show that.
Comments
Post a Comment