Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Writing FTP Client in Java

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
actually i posted a question "how to autmoate FTP using Java". i knew the script in Unix to write to automate FTP and all but i didn't want to use Runtime.exec() to do it so i wondered if there are any available APIs for FTP in Java...so i posted this question on "Java other APIs" forum but now i am thinking of writing my own FTP Client in Java...
can anybody suggest some steps i need to follow. i guess i 've to first understand FTP sematics etc which i'll do but if somebody has already written such client he/she can help me little so that i don't miss anything important.
i would love to learn writing FTP client...
regards,
maulin
 
Ranch Hand
Posts: 133
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at sun.net.ftp.*
And also look at this. It is really about SWING but provides an example of an FTP Client using the afore mentioned package.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
thanks a lot for pointers you provided.
i wrote my FTP Client in Java myself. Though I decompiled the sun.net.ftp.FtpClient
it was good to learn how FTP works and why people say it is not a secure protocol.
also, here is a link i found useful to understand FTP,
FTP
thanks,
maulin
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am getting the follwoing error while trying to upload a text file to FTP server using JAVA API.


java.io.FileNotFoundException: STOR c:\Test\FTP\testout\BLR.txt: 550 c:\Test\FTP\testout\B
LR.txt: Access is denied.

my Code
=============================================
import java.net.*;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.IOException;

class FtpTest
{
public void upload(){
try {

URL url = new URL("ftp://user assword@localhost/c:\\Vauxhalll\\FTP\\testin\\BLR.txt");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.connect();
OutputStream out = conn.getOutputStream();

FileInputStream fis = new FileInputStream("c:\\Vauxhalll\\FTP\\testin\\BLR.txt");
int b;
while ((b = fis.read()) != -1) {
out.write(b);
}
out.close();
fis.close();


} catch (IOException ie) {
System.out.println(ie);
}
}
public static void main(String[] args)
{
System.out.println("Hello World!");
FtpTest test = new FtpTest();
test.upload();
}
}
===============================================================
 
Bartender
Posts: 9586
13
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are attempting to read and write to/from the same file.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pani_pani2000,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request display names follow the pattern FIRST_NAME + SPACE + LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!
 
No holds barred. And no bars holed. Except this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!