I have found many posts on checking if the file on the ftp server exists. None of the codes provided helped. I am trying to auto upload small files to the ftp server BUT I don't want to override the file if it already exists. The following code works if the file already exists but if it doesn't it kicks back an error and does not run the code in the if statement.
System.Console.WriteLine("check if hash file is on ftp server " + hashfile);
string fileSize = ftpClient.getFileSize(hashfile);
int fSize =-1;
bool res = (Int32.TryParse(fileSize, out fSize));
if (res)
{
System.Console.WriteLine("Hash file is not on ftp server " + hashfile);
ftpClient.upload(hashfile, @hashfile);
ftpClient.upload(charfile, @charfile);
File.Delete(hashfile);
File.Delete(charfile);
}
else
{
System.Console.WriteLine("Hash file is on ftp server " + hashfile);
string newHashFile = "ntlmhash" + str_cint + "_" + str_pint + "_" + e + ".txt";
while (File.Exists(newHashFile))
{
e++;
newHashFile = "ntlmhash" + str_cint + "_" + str_pint + "_" + e + ".txt";
string FileSize = ftpClient.getFileSize(newHashFile);
int FSize =-1;
if (Int32.TryParse(FileSize, out FSize))
{
ftpClient.upload(newHashFile, @newHashFile);
ftpClient.upload(charfile, @charfile);
File.Delete(newHashFile);
File.Delete(charfile);
}
else
{
e++;
}
}
System.IO.File.Move(hashfile, newHashFile);
ftpClient.upload(newHashFile, @newHashFile);
ftpClient.upload(charfile, @charfile);
File.Delete(newHashFile);
File.Delete(charfile);
}