Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2004, 02:43 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
download a remote file to the local machine.

can someone point me in the right direction? i want to write a bench program to tell me how long it takes to download a file across a network.

i figure i can use the date object to determine the time, but i need to know what to use to download the file to the local computer.

if i find an answer, i'll post.
__________________
Mike
sde is offline   Reply With Quote
Old 11-04-2004, 06:13 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
Sorry, I can't think of something right now that would work apart from attempting to ping the host computer, and that doesn't sound feesible and especially so for a bandwidth test.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 11-04-2004, 06:18 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
last night i was messing with the URL object, but yeah, not working for a bandwidth test.

i'm thinking that i just need to execute a system command to copy a file from a network drive.

i got this working with c# last night, but i want to use it on a mac too. we're setting up a gigabit network within our network for the transfer of large video files. i'll update if i work anything out today.

thanks for the reply
__________________
Mike
sde is offline   Reply With Quote
Old 11-04-2004, 06:29 AM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
I assumed that this was for a website; I have done network benchmarking in Java before. It's just a matter of opening a socket and shoving through a known quantity of data.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 12-04-2004, 11:49 AM   #5 (permalink)
freesoft_2000
Code Monkey
 
Join Date: Oct 2004
Posts: 51
freesoft_2000 is on a distinguished road
Talking

hi everyone,

I don't know much about about other types of downloads except for ftp downloads. By the way you can use the below function as a way to get file sizes

Code:
import java.net.*;
import java.lang.reflect.*;
import sun.net.ftp.*;
import sun.net.*;

int getfilesize(FtpClient client, String filename){

//This function tries to get the file size of the currently
//uploaded or downloaded file

String str = "", token;
int c, index = 0;
char ch;
 
try
{
//The try statement is to try to catch any errors thrown by 
//the Java input and output

                   TelnetInputStream lst = client.list();
                    filename = filename.toLowerCase();

while(true)
{
            c = lst.read();
             ch = (char) c;
if((c < 0) || (ch == '\n'))
{
          str = str.toLowerCase();

if(str.indexOf(filename) >= 0)
{

              StringTokenizer tk = new StringTokenizer(str);

while(tk.hasMoreTokens())
{
                token = tk.nextToken();

if(index == 4)
{
//The try statement is to try to catch any errors thrown by 
//the Java input and output

try
{
            return Integer.parseInt(token);
}
//The catch statement is to try to catch any errors 
//thrown by the Java input and output
//by using the NumberFormatException constant

catch(NumberFormatException e)
{
        return -1;
}

}

          index++;

}

        str = "";

}

if(c <= 0)
{ 
        break;
}

       str += ch;
}

       return -1;

}

}
//The catch statement is to try to catch any errors
//thrown by the Java input and output
//by using the Exception constant

catch(Exception e1)
{
System.out.println("File size unknown");
}

       return -1;
}
I tried the function and it works and i hope it helps you. The function returns the current downloaded size of the file.

Please let me know what think of this function

Yours Sincerely

Richard West
freesoft_2000 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
steam a csv file for download. sde Java 1 07-27-2004 04:15 PM
File DownLoad in java Gopinath_java Java 1 06-19-2004 03:45 AM


All times are GMT -8. The time now is 12:12 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting