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.
jayz_smithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wannabetechieCommented:
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.
0
jayz_smithAuthor Commented:
hi wannabetechie :

as you said, apache commons-net library, do you have any sample code that ueses that ?
0
wannabetechieCommented:
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"
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

VenabiliCommented:
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?
0
wannabetechieCommented:
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.
0
VenabiliCommented:
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.
0
wannabetechieCommented:
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.
0
VenabiliCommented:
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)
0
wannabetechieCommented:
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.
0
jayz_smithAuthor Commented:
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 ?
0
jayz_smithAuthor Commented:
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 ?
0
VenabiliCommented:
>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.
0
VenabiliCommented:
SFTP is not FTP - it is SSH. So you cannot use FTP code for connecting to it.

http://www.spindriftpages.net/blog/dave/2007/11/27/sshtools-j2ssh-java-sshsftp-library/ has some code with the SSHTools.
0
wannabetechieCommented:
Just to add to Venabili's comment if you want use Jsch from JCraft you will find an example here

http://www.jscape.com/articles/secure_ftp_using_java.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jayz_smithAuthor Commented:
Thanks a lot guys
0
VenabiliCommented:
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.
0
VenabiliCommented:
You are welcome.

PS: Some Jsch examples are here: http://www.jcraft.com/jsch/examples/
0
jayz_smithAuthor Commented:
@ 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.