Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Ftp from servlet to client

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can someone please tell me how to ftp from a servlet to a client. I have tried Sun and Apache's ftp client classes, sockets and URLConnection. In all cases the ftp just results in the file being "ftp'd" to the root directory of my account on my web host. The snippet of code I am currently using with a URL Connection is:

BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL("ftp://user wd@ftpServer/fileName;type=i"); // i.e. ftp location URL
URLConnection urlc = url.openConnection();

bis = new BufferedInputStream(urlc.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));

int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}

///////////////////////////////

Do I need an additional connection to the client? If so, can I get an example?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe if you describe, exactly, what you are trying to do, someone could help.
A servlet is not going to be able to initiate an FTP session with a client unless the client is running an FTP Server.
 
Susan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
Maybe if you describe, exactly, what you are trying to do, someone could help.
A servlet is not going to be able to initiate an FTP session with a client unless the client is running an FTP Server.

 
Susan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a number of files on my anonymous ftp site on my web server. I want to programmatically download these to client machines without revealing the program locations.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like this....







Build the username/password into the ftp string like..
ftp://anonymous:someone_somewhere.com@ftpdomain.com/dir/filename..
[ March 20, 2005: Message edited by: Ben Souther ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Susan (moose) nospamthanks",
we're a friendly bunch here at the Ranch, but one rul we take quite seriously is the one about display names. You can read about it here.

Basically we require your display name to be two words: Your first name, a space, then your last name. Obviously fictitious names are not allowed.

Please edit your profile and select a valid display name. Acounts with invalid display names get deleted, often without warning

thanks,
Dave.
 
Susan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
Try something like this....







Build the username/password into the ftp string like..
ftp://anonymous:someone_somewhere.com@ftpdomain.com/dir/filename..

[ March 20, 2005: Message edited by: Ben Souther ]




Thanks I'll give it a try.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Susan Nospamthanks",
sorry, this is still fictitious and not allowed. Please try again.

thanks,
Dave.
 
Susan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have attempted the code as indicated above, however, although it got me to the point of saving the file to the client, the downloaded file was only 1K.

I set the mime content to "application/octet-stream" to indicate the files were of type "bin" and/or "exe". I have tried both the buffered byte read and the byte-by-byte file reads and it makes no difference. I have checked the ulimit on the host and it says "unlimited". Any idea what might be the problem?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Susan,
Out of respect for the moderators, who are trying to maintain a professional environment here, many people (myself included) will refrain from continuing converstaions with someone until they have complied with any outstanding requests from the said moderators.

(fix your name: <first-name> <last-name> )

-Ben
[ March 21, 2005: Message edited by: Ben Souther ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic