Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Move file from Windows to FtpServer(Unix)

 
Srinivasa Maddi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Srinivasa Maddi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for quick response.
But my requirement is not to use any third party jars here.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible to do FTP using URL/URLConnection as detailed in our File Upload FAQ
 
Srinivasa Maddi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the above directory exists and ofcourse i am able to login with the above credentials
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see my code below(correct me if i am wrong)



On running the same i am getting the below error:



 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to write directly to a folder.
 
Srinivasa Maddi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes because i want my file to be placed in that folder.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic