惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
T
Tenable Blog
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
P
Palo Alto Networks Blog
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
博客园_首页
D
Docker
MyScale Blog
MyScale Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
S
Schneier on Security
C
Check Point Blog
I
Intezer
S
Securelist
雷峰网
雷峰网
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
PCI Perspectives
PCI Perspectives
S
Security @ Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
量子位
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
About on SuperTechFans
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news

博客园 - 城

序列化成字符串 - 城 - 博客园 东北话 c# MD5加密 SubVersion的多库权限配置 Visual Studio .NET has detected Web server is not running ASP.NET 1.1(vs.2003) Unable to generate a temporary class (result=1).error CS2001: Source file '...... VS.net 2005快捷键一览表 Tsql123 Windows Service OnCustomCommand 的問題 vba控件常规使用 vba 中 加载DLL错误的解决方法 无法在Web服务器上启动调试。您不具备调试此应用程序的权限,此项目的URL位于Internet区域。 安装程序工具 (Installutil.exe) 文件上传 XML简单操作 WSE2.0加密Web Service soap验证 windows2003reg 在1433 以外的任何端口上连接到SQL Server
使用WebClient进行上传文件
· 2007-10-18 · via 博客园 - 城

   private bool UploadFile(string source,string targetUrl,NetworkCredential networkCredential)
        
{
            FileStream streamSource;
            Stream streamTarget;
            WebClient client 
= new WebClient();
            client.Credentials 
= networkCredential;
            
try
            
{
                streamSource 
= File.OpenRead(source);
            }

            
catch (Exception err)
            
{
                
return false;
            }

            
try
            
{
                Uri url 
= new Uri(targetUrl);
                streamTarget 
= client.OpenWrite(url, "PUT");
            }

            
catch (Exception err)
            
{
                
return false;
            }

            
try
            
{
                
long num = 0;
                
int count = 0;
                
byte[] buffer = new byte[512];
                
while (num < streamSource.Length)
                
{
                    count 
= streamSource.Read(buffer, 0512);
                    streamTarget.Write(buffer, 
0, count);
                    num 
+= count;
                    
                }

                streamTarget.Close();
                streamSource.Close();
                
return true;
            }

            
catch (Exception err)
            
{
                
return false;
            }

        }