Solved

FTP using Java

Posted on 2001-06-11
5
465 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 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

11 Experts available now in Live!

Get 1:1 Help Now