I want to read a file from a FTP server without downloading it to a local file. I wrote a function but it does not work:
private string GetServerVersion()
{
WebClient request = new WebClient();
string url = FtpPath + FileName;
string version = "";
request.Credentials = new NetworkCredential(ftp_user, ftp_pas);
try
{
byte[] newFileData = request.DownloadData(new Uri(FtpPath)+FileName);
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
}
catch (WebException e)
{
}
return version;
}
Here's a simple working example using your code to grab a file from the Microsoft public FTP servers:
I reckon you're missing a slash on this line here in your code:
Perhaps between
FtpPath
andFileName
?I know this is an old question, but I thought I'd suggest using path.combine for the next guy reading this. Helps clean up these kinds of issues.
We can use below method to get the file attribute from ftp without downloading the file.This is working fine for me.