Link to home
Start Free TrialLog in
Avatar of jayz_smith
jayz_smith

asked on

transfer a file from unix to windows

Hi all,

I have one file on unix location. I want to write a code in java to transfer that file to the perticual location in windows.

Any one can help me out with it ?

Thanks in advance.
Avatar of wannabetechie
wannabetechie
Flag of United States of America image

If you can ftp to the unix location try one of the solutions from this site

http://www.nsftools.com/tips/JavaFtp.htm

i think the easiest way would be to use apache commons-net library for ftp.
Avatar of jayz_smith
jayz_smith

ASKER

hi wannabetechie :

as you said, apache commons-net library, do you have any sample code that ueses that ?
Check out the link i mentioned earlier.In the last section you will find the sample code in the last section
"Option 4: Use the Jakarta Net classes"
The problem  with using these classes is that there should be an FTP server running on the windows box... and this is not always true. If there is an FTP server, the solution above will work as well as any other.

jayz_smith,

What is running on the Windows server? FTP server? SSH server? Something else?
Venabili:
 Why is a FTP server required on the windows box if he runs the program from the windows server and connects to the unix server using the FTP client.
Your comments above do not tell him which box to use for his program, does it? And the question is how to move from the Unix to the Windows one - so in most cases this means the program will be on the Unix one

Anyway - in case he can run it on the Windows box, then he will need the FTP server on the Unix box. And no - not every unix will have an FTP available...

One way or another, he needs an FTP server on one of the boxes and enough access with an account from it to get the file in order to use the commons method. Before some confirmation what is available, any proposed solution is more or less firing in the dark.
If you see my first comment that is exactly what i meant by saying
"If you can ftp to the unix location try one of the solutions from this site" and

"so in most cases this means the program will be on the Unix one" - i think this is as big as an assumption that if the file is there on a unix box then the program also should reside there.

But i do agree with your assessment that i could have been more explicit in stating from
where the FTP has to be done in the above mentioned solution.
Still does not say that he need to ftp from the windows box :) was just making sure that it is clear that a server is needed on one of the boxes.

Anyway - hopefully he has an SSH or FTP server running on at least one of the boxes - and a user account on it that can work with the file (because especially on the Unix box, permissions moght be a problem and I would not recommend anyone to go in as root if they can use something else)
Venabili:
 I agree with you completely that he needs to have permissions on the Unix box and logging in as root is   never a good idea.

jayz_smith:
Pls make sure that you have FTP or SFTP enabled on the Unix box before trying to connect to it from
any FTPClient program(in this case from the java program running in your windows box) and also the FTP user has permissions on the file you are trying to move.
Hi,

thanks for your reply. I tried to do it with option 4 as you said. it didn't go through.  The only thing I want to ask you is " if i want to get files from unix to windows, i need to use sftp, ain't I ? "  this was the example of FTP. u think will it work ?
Hi,

I have sftp enabaled on unix box for sure. but when I tried to debug the error, i came to know that it couldn't connect to the unix box. it says,

java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:168)
      at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:411)
      at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:453)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)
      at java.io.InputStreamReader.read(InputStreamReader.java:167)
      at java.io.BufferedReader.fill(BufferedReader.java:136)
      at java.io.BufferedReader.readLine(BufferedReader.java:299)
      at java.io.BufferedReader.readLine(BufferedReader.java:362)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
      at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:364)
      at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:540)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)
      at org.apache.commons.net.SocketClient.connect(SocketClient.java:268)
      at JakartaFtpWrapper.connectAndLogin(JakartaFtpWrapper.java:38)
      at one.main(one.java:15)

any idea ?
>if i want to get files from unix to windows, i need to use sftp, ain't I ?

You can use FTP as long as there is an FTP server there. If you have an SFTP instead, you can use Jscape or http://sourceforge.net/projects/sshtools/ or http://www.jcraft.com/jsch/ (for example)

and no - you cannot use the above solution for SFTP connections.
SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot guys
wannabetechie,

This example is for Jscape, not for Jsch :) And Jscape is not free: http://www.jscape.com/sshfactory/purchase.html

Although I like it when the budget allows it.
You are welcome.

PS: Some Jsch examples are here: http://www.jcraft.com/jsch/examples/
@ Venabili and wannabetechie : Thanks for your help. The sftp link you sent works perfect. But my requirement is I need to write a code to download perticualar file from unix to windows. The FTP link that wannabetechie sent works exactly as per my requirement. But in my unix box, ftp is blocked. so I must use sftp.

In my code works something like this :  Once user enter perticular criterion, based on that criterion I have to locate the file on unix box and I have to save that file to my local windows machine.

Hope you can help me out. Or I can open a new question with 500 points if you want....  

Thanks in advance.