This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

How to read a remote text file

 
Ranch Hand
Posts: 166
1
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have created a SSH Client with Java that connects to a remote Windows computer.

I want to read a text file which is on the remote computer with Java and print the text. Has anyone tried this before?

Thanks
Ioanna
 
Saloon Keeper
Posts: 5880
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what kind of API this client supports. Can you easily retrieve the output of a remote command that you send? Then you could just send a type command to the remote machine.
 
Saloon Keeper
Posts: 21266
138
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how a Linux(Unix) ssh client would do that against a remote Linux or Unix host:

ssh user@remotehost cat thefile.txt

If memory serves, Windows uses the "TYPE" command to list what's in a text file. Linux uses "cat" (it's an old joke and a cruel one), and "type" checks a file's type (not that that matters here).

However, Windows doesn't have a remote SSH server last time I remembered unless maybe PuTTY offers one as a third-party add-on. Which means that if your Java SSH app really does connect as an SSH client to a Windows computer, we need to know what on the Windows computer the Java app is talking to.
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're really using the SSH protocol, you should checkout JSch. If you're feeling experimental you can even try my SFTP file system to use the NIO.2 framework.
 
Ioanna Katsanou
Ranch Hand
Posts: 166
1
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone for your answers !!
In the end I didn't have to do this after all, but I used JSch to run a bat file on the Windows machine.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to Java World. Can you please explain in detail about SSH client and usage of Unix SSH client
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!