Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Uploading & Verifying

Reply
Thread Tools

Uploading & Verifying

 
 
H3li0
Guest
Posts: n/a
 
      11-05-2003
Hello,

Does anyone know how to upload files to a server via ftp *and* veryfying
that the file has been successfully uploaded?

How to do that with Java?

Any help/sample code would be appreciated.


Thanks in Advance.

Java Newbie


 
Reply With Quote
 
 
 
 
mromarkhan@rogers.com
Guest
Posts: n/a
 
      04-22-2004

Peace be unto you.

1.
Download
Commons Net from
http://jakarta.apache.org/site/binindex.cgi

2. Write this code
import org.apache.commons.net.ftp.FTPClient;
import java.io.*;
import org.apache.commons.net.ftp.FTPReply;
public class FTPThis
{
public static void main(String [] args)
{
FTPClient ftp = new FTPClient();
try
{
String server = "members.google.com";
String username="mromarkhan";
String password="x9s23msd0m3";
int reply;
ftp.connect(server);
ftp.login(username, password);
System.out.println("Connected to " + server + ".");
System.out.print(ftp.getReplyString());

// After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
System.out.println("PWD: " + ftp.printWorkingDirectory());
FileInputStream inputstream = new FileInputStream("c:/windows/desktop/quran.html");
if(ftp.storeFile("quran.html",inputstream))
{
System.out.println("Was uploaded");
}
else
{
System.out.println("Not uploaded");
}
}
catch(IOException e)
{
if(ftp.isConnected())
{
try
{
ftp.disconnect();
}
catch(IOException f)
{
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
System.exit(1);
}
}
}

3.
Realize that
"The convention for all the FTP command methods
in FTPClient is such that they
either return a boolean value or
some other value. The boolean methods
return true on a successful completion
reply from the FTP server and false on
a reply resulting in an error condition or failure."
- http://jakarta.apache.org/commons/ne...FTPClient.html

4. Run Show
javac -classpath "C:\downloads\commons-net-1.1.0\commons-net-1.1.0\commons-net-1.1.0.jar;." FTPThis.java
java -classpath "C:\downloads\commons-net-1.1.0\commons-net-1.1.0\commons-net-1.1.0.jar;." FTPThis

5. Produces
Connected to members.google.com.
230-User mromarkhan has group access to: httpd
230 OK. Current restricted directory is /
PWD: /
Was uploaded

Have a good day.
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      04-22-2004
On Thu, 22 Apr 2004 20:01:04 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 2. Write this code


<snip code>
> System.out.println("Connected to " + server + ".");
> System.out.print(ftp.getReplyString());
>
> // After connection attempt, you should check the reply code to verify
> // success.


Hi! I've noticed a few of your
code samples and had a play with
one.

[ They are fun, BTW ]

Could I just ask two (small) things
of you though?

1) Set the default 'wrap width' of
your newsreader a few less characters
so you do not post code lines as long
as the second last one there.

It may well line-wrap on some news readers
and becomes not 'copy-paste-compile' any more.

That would be a pity.

[My apologies in advance if you specifically
counted the chars and determined they fit
through a standard reader, it seems 83 chars,
whereas I _think_ you can only depend on the
'70's - but I am a bit hazy on the actual number. ]

2) Wrap your code in something like..
<code>
.....
</code>

[ I am looking at playing with classes
that can pull code straight from the Google
usenet archives into my on-line compiler,
and those tags would help me identify the
code easily! ]

Oh, and ..peace be unto you, as well.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Verifying DNS with Cisco 837 Doc Oakenfold Cisco 1 12-17-2008 01:05 PM
ftp uploading vs. control panel uploading Dung Ping HTML 10 01-16-2006 10:43 AM
Verifying someone is really certified. kb Microsoft Certification 3 07-30-2005 05:02 AM
verifying multicasting J R Cisco 3 09-02-2004 06:42 AM
Verifying Multicast Settings J R Cisco 2 08-20-2004 12:17 AM



Advertisments