I want to get a file from an FTP server, but when there is no Internet connection I want to get the file locally. When I force an FTP error, the C# program aborts. How can I “catch” this error? When I debug it, it goes to other c# scripts, such as ExecuteEvents.cs, and somewhere along the way it aborts. It never comes back to my script. When it gets to line:
string fileData = request.DownloadString(ftpPath);
it goes off into pre-packaged scripts and aborts. It works fine when I don’t force the FTP error.
string fileToFTP = “myFile.txt”;
string fileData = GetFTPFile.FtpFile(FileToFTP);
public class GetFtpFile : MonoBehaviour
{
public static string[ ] FtpFile(string fileToFTP)
{
string ftpPath = (@“ftp://myftphost.com/” + fileToFTP);
WebClient request = new WebClient
{
Credentials = new NetworkCredential(“username”, “password”)
};
string fileData = request.DownloadString(ftpPath);
return fileData;
}
}