Handling FTP exceptions like no internet etc Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Handling COM exceptions / busy codesKeeping UI responsive while performing long running taskEncapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?Replace strings in a fileHandling an invalid SQL query exceptionC++ alternative to exceptionsSecuring User Credentials in CookiesGenerate and store passwords securelyURL decode a string but log an error after second exceptionIsDatabaseUp returns true or throws exception
Why are current probes so expensive?
NIntegrate on a solution of a matrix ODE
The bible of geometry: Is there a modern treatment of geometries from the most primitive to the most advanced?
Weaponising the Grasp-at-a-Distance spell
One-one communication
Pointing to problems without suggesting solutions
Centre cell contents vertically
How do you write "wild blueberries flavored"?
systemd and copy (/bin/cp): no such file or directory
Is a copyright notice with a non-existent name be invalid?
Find general formula for the terms
Marquee sign letters
latest version of QGIS fails to edit attribute table of GeoJSON file
Why can't fire hurt Daenerys but it did to Jon Snow in season 1?
Is it OK to use the testing sample to compare algorithms?
How does TikZ render an arc?
Order between one to one functions and their inverses
Understanding piped command in Gnu/Linux
When does a function NOT have an antiderivative?
The test team as an enemy of development? And how can this be avoided?
Is there any significance to the prison numbers of the Beagle Boys starting with 176-?
Why weren't discrete x86 CPUs ever used in game hardware?
By what mechanism was the 2017 UK General Election called?
What are some likely causes to domain member PC losing contact to domain controller?
Handling FTP exceptions like no internet etc
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Handling COM exceptions / busy codesKeeping UI responsive while performing long running taskEncapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?Replace strings in a fileHandling an invalid SQL query exceptionC++ alternative to exceptionsSecuring User Credentials in CookiesGenerate and store passwords securelyURL decode a string but log an error after second exceptionIsDatabaseUp returns true or throws exception
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.
The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.
I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).
Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).
var ftp = StoryManager.MainWindow.FtpClient;
ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;
if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))
MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;
if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)
Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;
try
bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");
if (userDirExist)
try
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!projectsDirExist)
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!fileExist)
var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");
StoryManager.Add(new WelcomeScreen());
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
}
Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?
Edit 1
The Rest.LoginAsync method implementation is
public static async Task<User> LoginAsync(string usernameValue, string passwordValue)
try
var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new
username = usernameValue,
password = passwordValue
).ReceiveString();
var fields = result.Split(';');
switch (result)
case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;
User loggedUser = new User
IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;
return loggedUser;
catch (Exception ex)
Console.WriteLine(ex.ToString());
return null;
The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)
c# security error-handling wpf ftp
$endgroup$
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.
The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.
I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).
Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).
var ftp = StoryManager.MainWindow.FtpClient;
ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;
if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))
MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;
if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)
Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;
try
bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");
if (userDirExist)
try
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!projectsDirExist)
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!fileExist)
var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");
StoryManager.Add(new WelcomeScreen());
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
}
Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?
Edit 1
The Rest.LoginAsync method implementation is
public static async Task<User> LoginAsync(string usernameValue, string passwordValue)
try
var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new
username = usernameValue,
password = passwordValue
).ReceiveString();
var fields = result.Split(';');
switch (result)
case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;
User loggedUser = new User
IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;
return loggedUser;
catch (Exception ex)
Console.WriteLine(ex.ToString());
return null;
The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)
c# security error-handling wpf ftp
$endgroup$
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
2
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35
add a comment |
$begingroup$
I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.
The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.
I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).
Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).
var ftp = StoryManager.MainWindow.FtpClient;
ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;
if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))
MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;
if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)
Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;
try
bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");
if (userDirExist)
try
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!projectsDirExist)
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!fileExist)
var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");
StoryManager.Add(new WelcomeScreen());
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
}
Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?
Edit 1
The Rest.LoginAsync method implementation is
public static async Task<User> LoginAsync(string usernameValue, string passwordValue)
try
var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new
username = usernameValue,
password = passwordValue
).ReceiveString();
var fields = result.Split(';');
switch (result)
case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;
User loggedUser = new User
IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;
return loggedUser;
catch (Exception ex)
Console.WriteLine(ex.ToString());
return null;
The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)
c# security error-handling wpf ftp
$endgroup$
I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.
The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.
I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).
Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).
var ftp = StoryManager.MainWindow.FtpClient;
ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;
if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))
MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;
if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)
Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;
try
bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");
if (userDirExist)
try
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!projectsDirExist)
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
try
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
if (!fileExist)
var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");
StoryManager.Add(new WelcomeScreen());
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);
else
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
}
Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?
Edit 1
The Rest.LoginAsync method implementation is
public static async Task<User> LoginAsync(string usernameValue, string passwordValue)
try
var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new
username = usernameValue,
password = passwordValue
).ReceiveString();
var fields = result.Split(';');
switch (result)
case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;
User loggedUser = new User
IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;
return loggedUser;
catch (Exception ex)
Console.WriteLine(ex.ToString());
return null;
The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)
c# security error-handling wpf ftp
c# security error-handling wpf ftp
edited Feb 21 '18 at 10:34
ODB8
asked Feb 21 '18 at 9:24
ODB8ODB8
112
112
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
2
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35
add a comment |
2
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35
2
2
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
- I would add a variable
var ftpClient = StoryManager.MainWindow.FtpClient;to shorten the calls to FtpClient a bit - You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188006%2fhandling-ftp-exceptions-like-no-internet-etc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
- I would add a variable
var ftpClient = StoryManager.MainWindow.FtpClient;to shorten the calls to FtpClient a bit - You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)
$endgroup$
add a comment |
$begingroup$
- I would add a variable
var ftpClient = StoryManager.MainWindow.FtpClient;to shorten the calls to FtpClient a bit - You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)
$endgroup$
add a comment |
$begingroup$
- I would add a variable
var ftpClient = StoryManager.MainWindow.FtpClient;to shorten the calls to FtpClient a bit - You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)
$endgroup$
- I would add a variable
var ftpClient = StoryManager.MainWindow.FtpClient;to shorten the calls to FtpClient a bit - You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)
answered Feb 25 '18 at 17:01
Markus MeyerMarkus Meyer
211
211
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188006%2fhandling-ftp-exceptions-like-no-internet-etc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36
$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35