Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could use jcabi-ssh to scp files? #7

Closed
zhaozhiming opened this issue Oct 30, 2014 · 5 comments
Closed

Could use jcabi-ssh to scp files? #7

zhaozhiming opened this issue Oct 30, 2014 · 5 comments

Comments

@zhaozhiming
Copy link

Could use jcabi-ssh to scp files? if yes, please give some example code, thank you.

@yegor256
Copy link
Member

Good question. This is how I would do it:

import com.jcabi.log.Logger;
import com.jcabi.ssh.SSH;
shell.exec(
  String.format(
    "cat > %s",
    SSH.escape(file_name)
  ),
  new FileInputStream(file),
  Logger.stream(Level.INFO, true),
  Logger.stream(Level.WARNING, true)
);

@zhaozhiming
Copy link
Author

ok, thank you.

@davidhtien
Copy link

Could this example be explained in more detail? I don't really see what's going here. Also I want to scp a byte array that is currently stored in memory would that be possible?

@devent
Copy link

devent commented Jan 30, 2017

A little bit old, but here is the explanation.

cat > %s command will read input from stdin and save it in the file %s (that will be replaced by the real file name, stored in file_name). The stdin is streamed in from the created FileInputStream(file).

@lubars
Copy link

lubars commented Jun 6, 2017

Also effective:

String.format("tee %s", SSH.escape(file_name))

This has the advantage that you can prepend sudo if desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants