Solved

FTP using Java

Posted on 2001-06-11
5
478 Views
Last Modified: 2010-04-16
I need to know if it is possible to use a java based proghram that will allow capability to upload(ftp)
a file to a server on which the java based program does not sit.
i.e. to be able to upload from a client to a server other than the server on which the java program resides.

I have asked this question previously in asp section and am quite interested in hearing javva options also.
0
Comment
Question by:seoirse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:iDeb
ID: 6178523
If you make http requests to upload a file, then irrespective of the server implementation, the server will recieve the http request with the contents.....all that is entirely language independent......and in order to do this open a url connection to your server-side write the contents of the file's input stream.....also you might want to set the http header information(lookup the java docs for that).....though i'm not familiar with ASP but i'm sure ASP would have ways to handle http requests with content....
0
 
LVL 1

Expert Comment

by:jimsims
ID: 6178583
as long as the server has an ftp server running that will accept uploads, you are fine
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6178599
Hi,

In theory, this should be pretty straightforward. You create ftp java.net.URL to location where you want to upload and call URL.getConnection().getOutputStream() to get stream. Than just write your data to that stream. Probably you will need to call URL.getConnection().setDoOutput() before upload start. Uploading usually involves authentication though. Don't know all ways to login to FTP server, and don't know how to handle them in java. I found Java FAQ useful for similar questions. Check it out:
http://java.sun.com/people/linden/intro.html

Regards,
Igor Bazarny
Brainbench MVP for Java 1
www.brainbench.com
 
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6178612
At http://www.web-feats.com/classes/java/sourcecode/sourcecode5.htm you
can find a ftp package which is distributed under GPL.
0
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 50 total points
ID: 6180113
import sun.net.*;
import sun.net.ftp.*;
import java.io.*;


public class ftp_utility {

public ftp_utility () {
FtpClient fcMyFtp = new FtpClient();

try {
int ch;
fcMyFtp.openServer("myftpsite");
fcMyFtp.login("myname","mypassword");

TelnetInputStream tisList =
fcMyFtp.list();
while( (ch = tisList.read()) != -1 )
System.out.print((char)ch);
// ... other stuff.
fcMyFtp.cd("temp");
fcMyFtp.binary();

// writing a file:
FileInputStream fis = new
FileInputStream( "/home/gadio/temp/tempfile" );
TelnetOutputStream  tos =
fcMyFtp.put("tempfile.new");
byte buffer[] = new byte[1000];
int len;
while( (len = fis.read(buffer)) != -1 ) {
tos.write(buffer,0,len);
}
fis.close();
tos.close();

// reading a file:
FileOutputStream fos = new
FileOutputStream( "/home/gadio/temp/tempfi
le.read" );
TelnetInputStream   tis =
fcMyFtp.get("tempfile.new");
while( (len = tis.read(buffer)) != -1 ) {
fos.write(buffer,0,len);
}
tis.close();
fos.close();
} catch( IOException e ) {
e.printStackTrace();
}
}

public static void main(String args[]) {
ftp_utility f = new ftp_utility();
}
}


FTP:-


http://www.afu.com/t.java 
http://www.quateams.com/oro/developers/docs/NetComponents/api/Package-com.oroinc.net.ftp.html 
http://www.alphaworks.ibm.com/ab.nsf/bean/WebAccessor 

FTP with java to download file

http://forum.java.sun.com/forum?13@165.tfueaxn1bvv^0@.ee85f09/0 
http://forum.java.sun.com/forum?13@165.tfueaxn1bvv^0@.ee77fb6/0 
http://developer.java.sun.com/developer/techDocs/SearchData/qa/about_javas_ftp.html 

Courtesy :- gadio
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question