using:
Visual Studio 2008 with Rebex Components 2014 R2
Is there a comprehensive document on when ProblemDetected is handled during Upload() and when Upload() solely throws an exception?
For example, I notice if I attempt to upload the same file name twice to the server that Upload() throws an exception AND ProblemDetected is handled. However, when the computer loses network connectivity during upload via Upload(), Upload() throws an exception and ProblemDetected is not handled.
It would be useful to know what types of scenarios would cause these different behaviors for error handling.
I have provided basic code from my test project that illustrates what is described.
Thank you.
private const string IpAddress = "";
private const string UserName = "";
private const string Password = "";
private const string Directory = "";
private const int Port = 22;
private void SftpOnProblemDetected(object sender, SftpProblemDetectedEventArgs sftpProblemDetectedEventArgs)
{
MessageBox.Show(string.Format("{0}{1}{1}{2}", sftpProblemDetectedEventArgs.Exception, Environment.NewLine,
sftpProblemDetectedEventArgs.ProblemType));
}
private void RebexConnectLoginSetDirectory(Sftp sftp)
{
sftp.ProblemDetected += SftpOnProblemDetected;
sftp.Connect(IpAddress, Port, new SshParameters { AuthenticationMethods = SshAuthenticationMethod.Any });
sftp.Login(UserName, Password);
sftp.ChangeDirectory(Directory);
}
private void RebexSftpTransferInspectionSingle(string fileFullPath)
{
if (!File.Exists(fileFullPath))
{
MessageBox.Show(string.Format("'{0}' does not exist.", fileFullPath));
return;
}
var fileInfo = new FileInfo(fileFullPath);
using (var sftp = new Sftp())
{
RebexConnectLoginSetDirectory(sftp);
sftp.Upload(fileInfo.FullName, sftp.GetCurrentDirectory());
uxError.Text = string.Format("{0} * Detail: {1}Uploaded '{2}' to '{3}'", uxError.Text, Environment.NewLine, fileInfo.FullName,
sftp.GetCurrentDirectory());
sftp.Disconnect();
}
MessageBox.Show(string.Format("Upload Complete: '{0}'", fileFullPath));
}
private void uxSftpSingleTransfer_Click(object sender, EventArgs e)
{
try
{
Enabled = false;
string fileFullPath;
using (var openFileDialog = new OpenFileDialog())
{
var dialogResult = openFileDialog.ShowDialog();
if (dialogResult != DialogResult.OK) return;
fileFullPath = openFileDialog.FileName;
}
if (fileFullPath == null) return;
var result = MessageBox.Show(string.Format("Are you sure you want to transfer '{0}'?", fileFullPath), "confirm", MessageBoxButtons.YesNo);
if (result != DialogResult.Yes) return;
RebexSftpTransferInspectionSingle(fileFullPath);
}
catch (Exception exception)
{
MessageBox.Show(exception.ToString());
}
finally
{
Enabled = true;
}
}