Skip to content

Commit

Permalink
Properly handle FTP not connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Jan 19, 2024
1 parent 30de2f2 commit 411c419
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Refresher/Accessors/ConsolePatchAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Net;
using System.Net.Sockets;
using FluentFTP;
using Refresher.Exceptions;

namespace Refresher.Accessors;

Expand All @@ -15,7 +17,9 @@ public ConsolePatchAccessor(string remoteIp)
this._client = new FtpClient(remoteIp, "anonymous", "");
this._client.Config.LogToConsole = true;
this._client.Config.ConnectTimeout = 5000;
this._client.AutoConnect();

FtpProfile? profile = this._client.AutoConnect();
if (profile == null) throw new FTPConnectionFailureException();

this.IdpsFile = new Lazy<byte[]>(() =>
{
Expand Down
5 changes: 5 additions & 0 deletions Refresher/Exceptions/FTPConnectionFailureException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;

namespace Refresher.Exceptions;

public class FTPConnectionFailureException() : Exception("Could not connect to the FTP server.");
11 changes: 9 additions & 2 deletions Refresher/UI/ConsolePatchForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Net.Sockets;
using System.Reflection;
using Eto.Forms;
using Refresher.Accessors;
using Refresher.Exceptions;

namespace Refresher.UI;

Expand Down Expand Up @@ -56,14 +58,19 @@ private bool InitializePatchAccessor()
{
this.Accessor = new ConsolePatchAccessor(this._remoteAddress.Text.Trim());
}
catch (FTPConnectionFailureException)
{
MessageBox.Show("Could not connect to the FTP server likely due to the PS3 rejecting the connection.\nAre you sure the webMAN FTP server is running?", "Error");
return false;
}
catch(TimeoutException)
{
MessageBox.Show($"The FTP connection timed out while we were waiting for a response from the PS3.\nAre you sure the webMAN FTP server is running?", "Error");
MessageBox.Show("The FTP connection timed out while we were waiting for a response from the PS3.\nAre you sure the webMAN FTP server is running?", "Error");
return false;
}
catch(UriFormatException)
{
MessageBox.Show($"The IP address was unable to be parsed. Are you sure you typed it in correctly?", "Error");
MessageBox.Show("The IP address was unable to be parsed. Are you sure you typed it in correctly?", "Error");
return false;
}
catch(Exception ex)
Expand Down

0 comments on commit 411c419

Please sign in to comment.