File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Move file from Windows to FtpServer(Unix) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Move file from Windows to FtpServer(Unix)" Watch "Move file from Windows to FtpServer(Unix)" New topic
Author

Move file from Windows to FtpServer(Unix)

Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
Hi

I have written a java program which on running will ask the source path and dest path, giving so it will copy the list of files from source directory to dest directory. But here my requrement is to copy the files from my windows machine to a unix machine over ftp. I have all the required ip, userid, password, port number and ofcourse the dest directory of my ftpserver with me. Can anyone help me now further

Regards,
Maddy
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Check this old thread


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
Thanks for quick response.
But my requirement is not to use any third party jars here.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Srinivasa Maddi wrote:Thanks for quick response.
But my requirement is not to use any third party jars here.


That's really silly. But given that constraint: you need to learn about the FTP protocol, and implement the client half. It's relatively complicated protocol that uses two separate client/server connections. Here's the protocol reference. Have fun!


[Jess in Action][AskingGoodQuestions]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8915
    
    8

It's possible to do FTP using URL/URLConnection as detailed in our File Upload FAQ


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
I am getting the following exception on using the same

Exception in thread "main" java.io.FileNotFoundException: CWD export: 550 export: No such file or directory.

at sun.net.ftp.FtpClient.readReply(FtpClient.java:236)
at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:193)
at sun.net.ftp.FtpClient.issueCommandCheck(FtpClient.java:206)
at sun.net.ftp.FtpClient.cd(FtpClient.java:658)
at sun.net.www.protocol.ftp.FtpURLConnection.cd(FtpURLConnection.java:338)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(FtpURLConnection.java:477)
at Temp.ftpConnection(Temp.java:10)
at Temp.main(Temp.java:13)

My code

URL url = new URL("ftp://user:password@ftp_server_ip:/export/home/fcdev");

Could you please suggest me if i want to upload my files to /export/home/fcdev directory of the above ftp server. How can i code it.

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8915
    
    8

Does the directory /export/home/fcdev exist?
Can you log in with an FTP client using the credentials you've specified and navigate to that directory?
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
yes the above directory exists and ofcourse i am able to login with the above credentials
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8915
    
    8

Try following the directory with a slash:


On my FTP server, if I give a first-level directory (i.e. "/www"), the URL will return a directory listing. If I use a non-root directory (i.e. "/www/images"), just the directory name will throw a FileNotFoundException. If I add the slash (i.e. "/www/images/"), I get the directory list.
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
Please see my code below(correct me if i am wrong)



On running the same i am getting the below error:



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You're trying to write directly to a folder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
yes because i want my file to be placed in that folder.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Yes. But you should be following the folder name with the file name like

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Move file from Windows to FtpServer(Unix)