[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

FTP using Java

Posted on 2001-06-11
5
Medium Priority
?
499 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 200 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

Technology Partners: 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

834 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