The below code do connects to the server successfully. It is a working code.
Now for example is not the server avaliable. So I receive this error even that I have put
this in a try{}catch{}
The error is below, and I wonder how I can shut this error off so it isn´t shown in the software?
"The remote server returned an error: (500) Internal Server Error."
String^ currentLine = "";
String^ getText = "";
try
{
Chilkat::SFtp^ sftp = gcnew Chilkat::SFtp();
sftp->UnlockComponent("key");
sftp->ConnectTimeoutMs = 5000; // Set some timeouts, in milliseconds:
sftp->IdleTimeoutMs = 15000;
int port = 2222;
String^ hostname = "folder.hosting.com";
sftp->Connect(hostname, port);
sftp->AuthenticatePw("username","password");
sftp->InitializeSftp();
String^ handle1 = "";
try
{
handle1 = sftp->OpenFile("folder/File1.txt", "readOnly", "openExisting");
if( handle1 != nullptr ) //The file DOES exist
{
int numBytes = sftp->GetFileSize32(handle1, false, true);
getText = sftp->ReadFileText(handle1,numBytes,"ansi");
currentLine = getText;
}
}
catch(Exception^ ex){}
sftp->CloseHandle(handle1);
}
catch(Exception^ ex)
{
}