Solved

FTP using Java

Posted on 2001-06-11
5
470 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 48
even odd program using while loop 3 40
javap not working 8 44
expectj telnet failing 5 35
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

786 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