使用C从服务器获取文件到本地pc#
我的godaddy服务器中有一个文件,我需要将该文件移动到本地系统。示例:我的远程位置是192.xxx.xxx.xxx/Infoware/Images,我需要将一些图像从godaddy服务器中的“Images”文件夹移动到本地PC。如果我理解正确,您只需要下载一个文件 根据您尝试构建的应用程序的类型,您可以同步或异步地进行构建 不同之处在于,如果同步下载文件,程序/线程将等待下载完成,然后继续 如果异步下载文件,,则程序在下载文件时继续运行,下载完成后,您必须注意。优点是,如果您编写Windows窗体应用程序,它将保持反应性,您可以更新进度条等 对于只下载文件而不需要报告进度的控制台应用程序,同步方式就足够了 同步示例:使用C从服务器获取文件到本地pc#,c#,asp.net,C#,Asp.net,我的godaddy服务器中有一个文件,我需要将该文件移动到本地系统。示例:我的远程位置是192.xxx.xxx.xxx/Infoware/Images,我需要将一些图像从godaddy服务器中的“Images”文件夹移动到本地PC。如果我理解正确,您只需要下载一个文件 根据您尝试构建的应用程序的类型,您可以同步或异步地进行构建 不同之处在于,如果同步下载文件,程序/线程将等待下载完成,然后继续 如果异步下载文件,,则程序在下载文件时继续运行,下载完成后,您必须注意。优点是,如果您编写Window
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://example.com/myfile.txt", @"c:\myfile.txt");
private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://example.com/myfile.txt"), @"c:\myfile.txt");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}
异步示例:
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://example.com/myfile.txt", @"c:\myfile.txt");
private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://example.com/myfile.txt"), @"c:\myfile.txt");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}
示例来自:非常感谢,我得到了它。我需要下载一个文件,其中前7个字符作为我的入场号。我有一些图像,其中前7个字符作为注册学生的入场号。我需要下载特定学生的图像。请帮我解决这个问题。所以你需要先找到确切的文件名?也许你应该使用wget。也许这是相关的: