Click here to Skip to main content
16,005,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
How to create a file in a home directory with help of other host username and password or IP adress?


What I have tried:

package com.techstar.com;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

class UpDown{
public static void main(String[] args) throws UnknownHostException, IOException {
    String ipAddress = "192.168.15.49";
    InetAddress inet = InetAddress.getByName(ipAddress);

    System.out.println("Sending Ping Request to " + ipAddress);
    System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");

    ipAddress = "192.168.15.38";
    inet = InetAddress.getByName(ipAddress);

    System.out.println("Sending Ping Request to " + ipAddress);
    System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
}}
Posted
Updated 14-Jun-18 0:31am
v3

1 solution

You need a service running on the remote machine that supports creating files. This might be for example [S]FTP or a network file sharing protocol like SMB/CIFS and NFS.

Then use a client class for the selected protocol to connect to the service and perform the required actions.
 
Share this answer
 
Comments
Member 13809409 14-Jun-18 6:45am    
can i do with ssh username and password??
Jochen Arndt 14-Jun-18 6:58am    
When there is an SSH server running: Yes

But note that plain SSH usually opens a shell which has to be used for executing commands (your code must be able to receive and interpret the returned output).
Member 13809409 14-Jun-18 7:14am    
am not able to do please help me ..how to do that?
Jochen Arndt 14-Jun-18 7:35am    
How to do what?

I can explain how to do such in general:
- Select a client class for that protocol
- Read the documentation of that class
- Search the web for examples if there are none in the documentation
- Write the code (here: connect and communicate)
- Test it, debug it
- Fix it if necessary and possible; one step back
- If not possible, rethink the design and go back to one of the top items from this list
- Working as expected: Done

Here with a Linux shell accessed via SSH use an appropriate command like
touch ~/the_file_name_to_be_created
Member 13809409 15-Jun-18 1:14am    
i want to do with scp please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900