aspose file tools*
The moose likes Linux / UNIX and the fly likes jsch file copy from Linux to Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "jsch file copy from Linux to Windows" Watch "jsch file copy from Linux to Windows" New topic
Author

jsch file copy from Linux to Windows

robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Hi,
I want to copy a file from Linux machine (local m/c) to Windows remote m/c. What all is required for that (eg. ssh daemon etc)? I'm able to copy file from windows to linux using jcraft (jsch).
Pls help.
Thanks in anticipation.
Robbie
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Why not setup a samba server


Spritle Software Blogs
robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
is there any other way to achieve this? there must be licensing issues with Samba and i've to copy file from linux to windows from a shell file (like i could do using jcraft)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
The JCIFS library can do this from within Java code.


Ping & DNS - my free Android networking tools app
robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Thanks Ulf. Does that mean I've to first install Samba on my Linux box and then uske JCIFS library in my java code to copy the file. What service do i need to start on remote windows machine and how do i set that?

cheers
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
You don't need to install anything on either side. The only requirement is that on the Windows side the target directory must be shared, so that it's accessible over the network. But you can protect it with a username/password, so that shouldn't be a problem.
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
While we are on this topic. I will ask this question. I have a dual boot laptop with Windows XP Professional installed on one partition and RedHat Fedora Core 4 on another. I can access anything I want from my Windows partition while I am using Linux using auto mount. Is there something similar that I can do on the Windows side while I am working in Windows to access the Linux partition?


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
While we are on this topic. I will ask this question.

That's really not the same topic at all. Please do not hijack threads with unrelated questions - start a new topic.
robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Thanks Ulf. But how will the linux box recognise "smb://"?
Can you please send the url from where i can get the code to make connection to remote windows m/c. All the examples on http://jcifs.samba.org/src/examples/ like CopyTo.java etc use arguments that will be passed into copyTo() method but none tells how will the arguments look like. I'm sure i don't have to use property file for storing remote m/c info and all that can be done in single java file.
Thanks in advance.
[ March 24, 2006: Message edited by: robbie keane ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
The URL looks something like this:

smb://username assword@192.168.110.80/shared_directory/
robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Thanks Ulf but I'm getting error while copying file. It's the CopyTo.java code (from jcisf examples)

import jcifs.smb.SmbFile;
public class CopyTo {
public static void main( String argv[] ) throws Exception {
SmbFile from = new SmbFile( argv[0] );
SmbFile to = new SmbFile( argv[1] );
from.copyTo( to );
}
}
and when i run the command on linux m/c
java CopyTo smb://username:loginPswd@172.19.47.101/usr/java/z.txt smb://username:loginPswd@172.19.39.53/share/deploy
I get the foll exception
Exception in thread "main" jcifs.smb.SmbException:
jcifs.util.transport.TransportException
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:178)
at jcifs.smb.SmbTransport.ssn139(SmbTransport.java:178)
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:236)
at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:301)
at jcifs.util.transport.Transport.run(Transport.java:223)
at java.lang.Thread.run(Thread.java:595)

at jcifs.util.transport.Transport.run(Transport.java:239)
at java.lang.Thread.run(Thread.java:595)

at jcifs.smb.SmbTransport.connect(SmbTransport.java:288)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:132)
at jcifs.smb.SmbFile.connect(SmbFile.java:791)
at jcifs.smb.SmbFile.connect0(SmbFile.java:761)
at jcifs.smb.SmbFile.copyTo(SmbFile.java:2005)
at CopyTo.main(CopyTo.java:9)

Please help.
cheers
[ April 02, 2006: Message edited by: robbie keane ]
vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 80

Hi robbie,

Can you please tell me how to transfer file from windows to linux using jcraft(jsch)?

Lovely Chhabr
Greenhorn

Joined: Jun 27, 2011
Posts: 1
Hi robbie,

I'm still having problems doing this - getting the same exception as you've mentioned.

Did anybody got a solution for this?

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsch file copy from Linux to Windows