혹시 C#인데요
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net;
using System.Web;
using System.Threading;
using System.IO;
namespace smart
{
public partial class update_form : Form
{
private long 받은파일싸이즈 = 0;
private long 총파일싸이즈 = 0;
private long 원본싸이즈;
private long 받을싸이즈;
private long 초당받은싸이즈;
private long 서버파일크기;
private long 걸린시간;
private string Constr = @"server=주소;uid=아이디;pwd=비번;database=데이타베이스";
public update_form()
{
InitializeComponent();
SqlConnection Conn = new SqlConnection(Constr);
Conn.Open();
string sql = "select * from tbldata where pkid=244";
SqlCommand Comm = new SqlCommand(sql, Conn);
SqlDataReader myRead = Comm.ExecuteReader();
myRead.Read();
string save_filename = myRead["filename"].ToString();
txtlink.Text = "http://beta.mapcenter.co.kr/down/" + save_filename;
textBox1.Text = String.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Personal), save_filename); //초기 저장될 폴더 설정"내문서"
Conn.Close();
}
private FileStream gFS;
private string url_path;
private void btnstart_Click(object sender, EventArgs e)
{
download();
/*
string[] strFileName = this.txtlink.Text.Split(new Char[] { '/' });
System.Array.Reverse(strFileName);
Uri uri = new Uri(this.txtlink.Text);
string str = WebClient.DownloadString(uri); //파일의 유효성 검사를 위한 코드
WebClient.DownloadFileAsync(uri, strFileName[0]);
*/
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection Conn = new SqlConnection(Constr);
Conn.Open();
string sql = "select * from tbldata where pkid=244";
SqlCommand Comm = new SqlCommand(sql, Conn);
SqlDataReader myRead = Comm.ExecuteReader();
myRead.Read();
string save_filename = myRead["filename"].ToString();
Conn.Close();
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog1.Filter = "All Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.FileName = save_filename;
if (saveFileDialog1.ShowDialog() == DialogResult.OK) // 파일선택후 저장버튼을 누르면
{
textBox1.Text = saveFileDialog1.FileName; // 텍스트박스에 파일경로및 파일명표시.
}
}
private delegate void tempData();
private delegate void tempData1();
public void download()
{
long tmpFileSize;
long startPoint;
const int LENGTH = 1024;
const int OFFSET = 0;
byte[] buffer = new byte[LENGTH];
int rcvd = 0;
url_path = txtlink.Text;
FileInfo gFI = new FileInfo(textBox1.Text);
gFI = new FileInfo(textBox1.Text);
if (!gFI.Exists) // 파일이 없을 경우
{
Stream st = File.Create(textBox1.Text); //일단 파일 생성해 놓쿠
st.Close();
startPoint = 0; // 새로 만들었으니 스타트 포인트는 0으로
}
else // 파일이 있을경우 이어받기를 위해
{
tmpFileSize = gFI.Length; // 받은 파일 싸이즈 구해서
startPoint = tmpFileSize + 1; // 받을 파일 싸이즈 다음(+1)으로 스타트 포인트 설정
총파일싸이즈 = tmpFileSize; // 받아진 총파일싸이즈
}
Get_URL_Size(); // 서버의 파일 싸이즈 구해라.
if (서버파일크기 != 총파일싸이즈) // 총 파일 싸이즈와 원본(서버의)싸이즈가 같지 않다면 이어받기.
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url_path); // Request 할 경로 설정
req.AddRange((int)startPoint); // 서버에서 날려줄 파일의 시작지점 설정
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); // Request보내고
Stream stream = resp.GetResponseStream(); // Response 받아서 스트림에
gFS = new FileStream(textBox1.Text, FileMode.Open); // 저장될 파일 스트림으로
gFS.Seek(startPoint, SeekOrigin.Begin); // 저장될 파일의 시작지점 설정
받을싸이즈 = resp.ContentLength;
원본싸이즈 = 받을싸이즈 + startPoint;
long statr_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 초당 속도를 표현하기 위한 시간 시작값
while (true)
{
rcvd = 0;
byte[] buff = new byte[LENGTH];
rcvd = stream.Read(buff, OFFSET, LENGTH); // 날라온거 읽어서
if (rcvd > 0) //날라온게 있으면
{
gFS.Write(buff, 0, rcvd); // 파일에 쓰고
받은파일싸이즈 += rcvd; //말안해도..^^;;
총파일싸이즈 += rcvd; //말안해도..^^;;
long end_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 초당 속도를 표현하기 위한 걸린 시간값
걸린시간 = end_time - statr_time; // 계산
if (걸린시간 > 0) // 1초가 지났으면
{
statr_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 시간 시작값 재 설정
}
초당받은싸이즈 += 1024; //말안해도..^^;;
}
else
{
gFS.Close(); // 없으면 파일 닫고
break; // 루프 끝네라
}
tempData mt = new tempData(게이즈바); // progressBar 및 속도 & 크기를 변경
this.Invoke(mt);
}
stream.Close();
resp.Close();
MessageBox.Show("전송완료");
}
}
public void 게이즈바()
{
int d = 0;
int e = 0;
if (원본싸이즈 != 0)
{
d = Convert.ToInt32((총파일싸이즈 * 100) / 원본싸이즈);
e = Convert.ToInt32((받은파일싸이즈 * 100) / 받을싸이즈);
}
progressBar1.Value = d;
progressBar2.Value = e;
label1.Text = String.Format("{0}", 서버파일크기 - (받을싸이즈 - 받은파일싸이즈));
label4.Text = String.Format("{0}", 받을싸이즈 - 받은파일싸이즈);
if (걸린시간 > 0) //1초가 지났으면 속도표시 바꿔라..
{
label12.Text = String.Format("{0}", 초당받은싸이즈 / 걸린시간); // 지연으로 인하여 걸린시간이(1024받는데) 1초 이상일 경우 나누어 주기...
초당받은싸이즈 = 0; // 초기화
}
}
private void Get_URL_Size()
{
HttpWebRequest req1 = (HttpWebRequest)WebRequest.Create(url_path); // Request 할 경로 설정
HttpWebResponse resp1 = (HttpWebResponse)req1.GetResponse(); // Request보내고
서버파일크기 = resp1.ContentLength; // 크기 저장
}
private void btnstop_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
이렇게 짠건데요
여기서 작은파일 다운로드하면 잘 되는데
큰 파일 다운로드하면 자꾸 응답없음처럼 화면이 표시가 되거든요
다운은 되고는있는데 미치겠네요
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net;
using System.Web;
using System.Threading;
using System.IO;
namespace smart
{
public partial class update_form : Form
{
private long 받은파일싸이즈 = 0;
private long 총파일싸이즈 = 0;
private long 원본싸이즈;
private long 받을싸이즈;
private long 초당받은싸이즈;
private long 서버파일크기;
private long 걸린시간;
private string Constr = @"server=주소;uid=아이디;pwd=비번;database=데이타베이스";
public update_form()
{
InitializeComponent();
SqlConnection Conn = new SqlConnection(Constr);
Conn.Open();
string sql = "select * from tbldata where pkid=244";
SqlCommand Comm = new SqlCommand(sql, Conn);
SqlDataReader myRead = Comm.ExecuteReader();
myRead.Read();
string save_filename = myRead["filename"].ToString();
txtlink.Text = "http://beta.mapcenter.co.kr/down/" + save_filename;
textBox1.Text = String.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Personal), save_filename); //초기 저장될 폴더 설정"내문서"
Conn.Close();
}
private FileStream gFS;
private string url_path;
private void btnstart_Click(object sender, EventArgs e)
{
download();
/*
string[] strFileName = this.txtlink.Text.Split(new Char[] { '/' });
System.Array.Reverse(strFileName);
Uri uri = new Uri(this.txtlink.Text);
string str = WebClient.DownloadString(uri); //파일의 유효성 검사를 위한 코드
WebClient.DownloadFileAsync(uri, strFileName[0]);
*/
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection Conn = new SqlConnection(Constr);
Conn.Open();
string sql = "select * from tbldata where pkid=244";
SqlCommand Comm = new SqlCommand(sql, Conn);
SqlDataReader myRead = Comm.ExecuteReader();
myRead.Read();
string save_filename = myRead["filename"].ToString();
Conn.Close();
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog1.Filter = "All Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.FileName = save_filename;
if (saveFileDialog1.ShowDialog() == DialogResult.OK) // 파일선택후 저장버튼을 누르면
{
textBox1.Text = saveFileDialog1.FileName; // 텍스트박스에 파일경로및 파일명표시.
}
}
private delegate void tempData();
private delegate void tempData1();
public void download()
{
long tmpFileSize;
long startPoint;
const int LENGTH = 1024;
const int OFFSET = 0;
byte[] buffer = new byte[LENGTH];
int rcvd = 0;
url_path = txtlink.Text;
FileInfo gFI = new FileInfo(textBox1.Text);
gFI = new FileInfo(textBox1.Text);
if (!gFI.Exists) // 파일이 없을 경우
{
Stream st = File.Create(textBox1.Text); //일단 파일 생성해 놓쿠
st.Close();
startPoint = 0; // 새로 만들었으니 스타트 포인트는 0으로
}
else // 파일이 있을경우 이어받기를 위해
{
tmpFileSize = gFI.Length; // 받은 파일 싸이즈 구해서
startPoint = tmpFileSize + 1; // 받을 파일 싸이즈 다음(+1)으로 스타트 포인트 설정
총파일싸이즈 = tmpFileSize; // 받아진 총파일싸이즈
}
Get_URL_Size(); // 서버의 파일 싸이즈 구해라.
if (서버파일크기 != 총파일싸이즈) // 총 파일 싸이즈와 원본(서버의)싸이즈가 같지 않다면 이어받기.
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url_path); // Request 할 경로 설정
req.AddRange((int)startPoint); // 서버에서 날려줄 파일의 시작지점 설정
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); // Request보내고
Stream stream = resp.GetResponseStream(); // Response 받아서 스트림에
gFS = new FileStream(textBox1.Text, FileMode.Open); // 저장될 파일 스트림으로
gFS.Seek(startPoint, SeekOrigin.Begin); // 저장될 파일의 시작지점 설정
받을싸이즈 = resp.ContentLength;
원본싸이즈 = 받을싸이즈 + startPoint;
long statr_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 초당 속도를 표현하기 위한 시간 시작값
while (true)
{
rcvd = 0;
byte[] buff = new byte[LENGTH];
rcvd = stream.Read(buff, OFFSET, LENGTH); // 날라온거 읽어서
if (rcvd > 0) //날라온게 있으면
{
gFS.Write(buff, 0, rcvd); // 파일에 쓰고
받은파일싸이즈 += rcvd; //말안해도..^^;;
총파일싸이즈 += rcvd; //말안해도..^^;;
long end_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 초당 속도를 표현하기 위한 걸린 시간값
걸린시간 = end_time - statr_time; // 계산
if (걸린시간 > 0) // 1초가 지났으면
{
statr_time = System.DateTime.Now.Ticks * 100 / 1000000000; // 시간 시작값 재 설정
}
초당받은싸이즈 += 1024; //말안해도..^^;;
}
else
{
gFS.Close(); // 없으면 파일 닫고
break; // 루프 끝네라
}
tempData mt = new tempData(게이즈바); // progressBar 및 속도 & 크기를 변경
this.Invoke(mt);
}
stream.Close();
resp.Close();
MessageBox.Show("전송완료");
}
}
public void 게이즈바()
{
int d = 0;
int e = 0;
if (원본싸이즈 != 0)
{
d = Convert.ToInt32((총파일싸이즈 * 100) / 원본싸이즈);
e = Convert.ToInt32((받은파일싸이즈 * 100) / 받을싸이즈);
}
progressBar1.Value = d;
progressBar2.Value = e;
label1.Text = String.Format("{0}", 서버파일크기 - (받을싸이즈 - 받은파일싸이즈));
label4.Text = String.Format("{0}", 받을싸이즈 - 받은파일싸이즈);
if (걸린시간 > 0) //1초가 지났으면 속도표시 바꿔라..
{
label12.Text = String.Format("{0}", 초당받은싸이즈 / 걸린시간); // 지연으로 인하여 걸린시간이(1024받는데) 1초 이상일 경우 나누어 주기...
초당받은싸이즈 = 0; // 초기화
}
}
private void Get_URL_Size()
{
HttpWebRequest req1 = (HttpWebRequest)WebRequest.Create(url_path); // Request 할 경로 설정
HttpWebResponse resp1 = (HttpWebResponse)req1.GetResponse(); // Request보내고
서버파일크기 = resp1.ContentLength; // 크기 저장
}
private void btnstop_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
이렇게 짠건데요
여기서 작은파일 다운로드하면 잘 되는데
큰 파일 다운로드하면 자꾸 응답없음처럼 화면이 표시가 되거든요
다운은 되고는있는데 미치겠네요
댓글 2개
17년 전
서버쪽 문제 인듯한데.
elvis
17년 전
험... 소스를 눈으로 보면서 하나하나 다 디버깅을 못하겟네요...
전 근데 C 프로그래머라서 C#에 대해서 정확하지 않지만 다운로드하는 쓰레드를 따로 구현해야 되지 않나요
화면 그리는 쓰레드(원래 app 뜰때 생성되는 쓰레드)랑 다운로드하는 쓰레드(새로 생성)랑 보통 분리하거덩요
전 근데 C 프로그래머라서 C#에 대해서 정확하지 않지만 다운로드하는 쓰레드를 따로 구현해야 되지 않나요
화면 그리는 쓰레드(원래 app 뜰때 생성되는 쓰레드)랑 다운로드하는 쓰레드(새로 생성)랑 보통 분리하거덩요
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1530 |
1111111
|
18년 전 | 1970 | |
| 1529 |
행복속네잎크로버
|
18년 전 | 3472 | |
| 1528 |
행복속네잎크로버
|
18년 전 | 1858 | |
| 1527 |
1111111
|
18년 전 | 7652 | |
| 1526 |
1111111
|
18년 전 | 3288 | |
| 1525 |
행복속네잎크로버
|
18년 전 | 1270 | |
| 1524 |
행복속네잎크로버
|
18년 전 | 2313 | |
| 1523 |
행복속네잎크로버
|
18년 전 | 3514 | |
| 1522 |
행복속네잎크로버
|
18년 전 | 2368 | |
| 1521 |
행복속네잎크로버
|
18년 전 | 2146 | |
| 1520 |
행복속네잎크로버
|
18년 전 | 2767 | |
| 1519 |
행복속네잎크로버
|
18년 전 | 3723 | |
| 1518 |
행복속네잎크로버
|
18년 전 | 3492 | |
| 1517 |
행복속네잎크로버
|
18년 전 | 2574 | |
| 1516 |
행복속네잎크로버
|
18년 전 | 1924 | |
| 1515 |
행복속네잎크로버
|
18년 전 | 1946 | |
| 1514 |
행복속네잎크로버
|
18년 전 | 2516 | |
| 1513 |
행복속네잎크로버
|
18년 전 | 1994 | |
| 1512 | 18년 전 | 2884 | ||
| 1511 | 18년 전 | 1670 | ||
| 1510 | 18년 전 | 2208 | ||
| 1509 | 18년 전 | 1686 | ||
| 1508 | 18년 전 | 2140 | ||
| 1507 | 18년 전 | 2367 | ||
| 1506 | 18년 전 | 2300 | ||
| 1505 | 18년 전 | 2252 | ||
| 1504 | 18년 전 | 2179 | ||
| 1503 | 18년 전 | 3490 | ||
| 1502 | 18년 전 | 1672 | ||
| 1501 | 18년 전 | 3442 | ||
| 1500 | 18년 전 | 2033 | ||
| 1499 | 18년 전 | 5297 | ||
| 1498 | 18년 전 | 2163 | ||
| 1497 |
hsp1980
|
18년 전 | 2346 | |
| 1496 |
hsp1980
|
18년 전 | 1732 | |
| 1495 |
hsp1980
|
18년 전 | 2135 | |
| 1494 |
hsp1980
|
18년 전 | 3651 | |
| 1493 | 18년 전 | 1506 | ||
| 1492 | 18년 전 | 1749 | ||
| 1491 | 18년 전 | 4325 | ||
| 1490 | 18년 전 | 3712 | ||
| 1489 | 18년 전 | 3269 | ||
| 1488 | 18년 전 | 3372 | ||
| 1487 |
mixdesign
|
18년 전 | 3869 | |
| 1486 |
mixdesign
|
18년 전 | 4331 | |
| 1485 | 18년 전 | 4262 | ||
| 1484 | 18년 전 | 2703 | ||
| 1483 |
hsp1980
|
18년 전 | 2317 | |
| 1482 |
hsp1980
|
18년 전 | 3250 | |
| 1481 |
hsp1980
|
18년 전 | 3169 | |
| 1480 |
hsp1980
|
18년 전 | 3322 | |
| 1479 | 18년 전 | 3257 | ||
| 1478 |
|
18년 전 | 4926 | |
| 1477 |
|
18년 전 | 5217 | |
| 1476 | 18년 전 | 3414 | ||
| 1475 |
mixdesign
|
18년 전 | 2722 | |
| 1474 |
mixdesign
|
18년 전 | 2941 | |
| 1473 |
mixdesign
|
18년 전 | 2276 | |
| 1472 |
mixdesign
|
18년 전 | 2088 | |
| 1471 |
mixdesign
|
18년 전 | 2044 | |
| 1470 |
|
18년 전 | 3077 | |
| 1469 |
mixdesign
|
18년 전 | 2359 | |
| 1468 |
mixdesign
|
18년 전 | 2382 | |
| 1467 |
mixdesign
|
18년 전 | 2063 | |
| 1466 |
mixdesign
|
18년 전 | 2431 | |
| 1465 |
mixdesign
|
18년 전 | 3159 | |
| 1464 | 18년 전 | 4088 | ||
| 1463 | 18년 전 | 3384 | ||
| 1462 |
|
18년 전 | 2007 | |
| 1461 |
|
18년 전 | 1947 | |
| 1460 | 18년 전 | 2865 | ||
| 1459 | 18년 전 | 1659 | ||
| 1458 |
|
18년 전 | 2015 | |
| 1457 |
mixdesign
|
18년 전 | 2312 | |
| 1456 |
mixdesign
|
18년 전 | 2171 | |
| 1455 | 18년 전 | 2294 | ||
| 1454 | 18년 전 | 4049 | ||
| 1453 | 18년 전 | 1789 | ||
| 1452 | 18년 전 | 4406 | ||
| 1451 | 18년 전 | 2942 | ||
| 1450 | 18년 전 | 2226 | ||
| 1449 | 18년 전 | 3269 | ||
| 1448 | 18년 전 | 2907 | ||
| 1447 | 18년 전 | 2835 | ||
| 1446 | 18년 전 | 5641 | ||
| 1445 | 18년 전 | 2305 | ||
| 1444 | 18년 전 | 3421 | ||
| 1443 |
|
18년 전 | 3334 | |
| 1442 | 18년 전 | 3720 | ||
| 1441 | 18년 전 | 3272 | ||
| 1440 | 18년 전 | 2453 | ||
| 1439 | 18년 전 | 2099 | ||
| 1438 | 18년 전 | 2551 | ||
| 1437 | 18년 전 | 6118 | ||
| 1436 | 18년 전 | 2740 | ||
| 1435 | 18년 전 | 4548 | ||
| 1434 | 18년 전 | 2052 | ||
| 1433 | 18년 전 | 10049 | ||
| 1432 | 18년 전 | 2496 | ||
| 1431 |
Psychedelico
|
18년 전 | 1555 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기