• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to read a remote text file

 
Ranch Hand
Posts: 182
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7631
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28101
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22799
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 182
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic