Reputation: 6908
I'm looking for a way, if possible, to connect to an ftp server, and then iterate through a list of local files to check their existence on the server. Now, I've found:
var request = (FtpWebRequest)WebRequest.Create("ftp://ftp.domain.com/doesntexist.txt");
request.Credentials = new NetworkCredential("user", "pass");
request.Method = WebRequestMethods.Ftp.GetFileSize;
try
{
var response = (FtpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
var response = (FtpWebResponse)ex.Response;
if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
{
//Does not exist
}
}
But, if I read this right (I haven't had my coffee yet), it creates a WebRequest
for each file. The overall goal is to check if these files exist, and if not, upload them. My question is, do I HAVE to do this individually, or is it possible(or even feasible) to just connect to the FTP once and then do my check/uploads?
Upvotes: 0
Views: 2055