Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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 ]
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic