Hi,
I have a code where I upload a file to a server. The code is shown below.
As seen I use a loop to try to connect 10 times if attempts is failing.
I have also put this in a try/catch block and at the end, I am showing a messagebox with confirmation that the file was created on the server.
The problem is this now. Sometimes the file is created and sometimes the file is Not created.
When the file is Not created, the messageBox is shown anyway. This is what I dont understand and that is the problem.
If the code have reached the messageBox it means that the above code has succeded but that is not the case, the file is not created on the serverpath.
How can this happen and can be done ?
Thank you...
for( int i = 0; i < 10; i++ ) //try 10 times
{
Thread::Sleep(200);
try
{
String^ LongString = "stringWithText";
Chilkat::SFtp^ sftp = gcnew Chilkat::SFtp();
sftp->UnlockComponent("dummy");
sftp->ConnectTimeoutMs = 5000; //Set some timeouts, in milliseconds:
sftp->IdleTimeoutMs = 15000;
int port = 2222;
String^ hostname = "dummy.hostname.com";
sftp->Connect(hostname, port);
sftp->AuthenticatePw("userName","passWord");
sftp->InitializeSftp(); //After authenticating, the SFTP subsystem must be initialized:
String^ handle1 = sftp->OpenFile("Folder1/Folder2/testFile.txt", "writeOnly", "createTruncate");
sftp->WriteFileText(handle1,"ansi", LongString); //Write some text to the file:
sftp->CloseHandle(handle1);
MessageBox::Show("Successfully sent", "Info ", MessageBoxButtons::OK, MessageBoxIcon::Information);
Application::DoEvents();
this->Close();
break;
}
catch(Exception^ ex){}
}