Solved

FTP using Java

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now