2010-01-26 7 views
0

J'essaie d'utiliser C# FtpWebRequest pour télécharger un fichier. Je ne veux pas télécharger à moins que la version du fichier dans le site de téléchargement soit supérieure à la version actuelle du fichier. Comment puis-je vérifier/obtenir la version du fichier sur le serveur distant?C# FtpWebRequest Vérification de la version du fichier

Répondre

1

 
Only .exe and .dll files have version info, which can be read by using 
FileVersionInfo..::.GetVersionInfo(). Text files do not have version info. 
Also, in order to read this version info, you'll have to download the file 
to a temp location.

Alternately, you can use the LastModifiedDate of the file to check if it is more recent. That will work for any type of file and can be done directly at the FTP site w/o downloading the file:

string requestUriString = BuildRequestUriString(ServerName, Path, fileName); 
FtpWebRequest aRequest = (FtpWebRequest) WebRequest.Create(requestUriString) 
aRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp; 
... 

using (FtpWebResponse aResponse = (FtpWebResponse) aRequest.GetResponse()) 
{ 
    return aResponse.LastModified; 
} 

Questions connexes