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
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!
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.
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
posted
0
Please see my code below(correct me if i am wrong)