WebClient request = new WebClient();
request.Credentials = new NetworkCredential("d","d");
request.DownloadFile("ftp://172.17.2.158/aa.xls",@"D:\abc.xls");FTP:用DownloadFile方法是否能下载?
request.Credentials = new NetworkCredential("d","d");
request.DownloadFile("ftp://172.17.2.158/aa.xls",@"D:\abc.xls");FTP:用DownloadFile方法是否能下载?
request.DownloadFile("ftp://username:[email protected]/aa.xls",@"D:\abc.xls");
public bool DownLoadFileFromServer(Uri serverUri)
{
string fileName = @"c:\aa.txt"; // Be saved local file //*************************************************************
// The serverUri parameter should start with the ftp:// scheme.
//*************************************************************
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
//*************************************************************
// Get the object used to communicate with the server.
//*************************************************************
WebClient request = new WebClient(); //*************************************************************
// This example assumes the FTP site uses anonymous logon.
//*************************************************************
request.Credentials = new NetworkCredential("wangjianfei", "1");
try
{
request.DownloadFile(serverUri, fileName);
byte[] newFileData = request.DownloadData(serverUri.ToString());
//*************************************************************
// Display the downloaded data.
//*************************************************************
string download = Encoding.ASCII.GetString(newFileData);
Console.WriteLine(download); string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
Console.WriteLine(fileString);
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return true;
}