Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsch file copy from Linux to Windows

 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not setup a samba server
 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JCIFS library can do this from within Java code.
 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 493
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL looks something like this:

smb://username assword@192.168.110.80/shared_directory/
 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi robbie,

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

 
Lovely Chhabr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic