|
|
@@ -478,148 +478,160 @@ void __fastcall TTerminal::Open()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- ResetConnection();
|
|
|
- FStatus = ssOpening;
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
- if (FFileSystem == NULL)
|
|
|
- {
|
|
|
- Log->AddStartupInfo();
|
|
|
- }
|
|
|
-
|
|
|
- assert(FTunnel == NULL);
|
|
|
- if (FSessionData->Tunnel)
|
|
|
- {
|
|
|
- DoInformation(LoadStr(OPEN_TUNNEL), true);
|
|
|
- LogEvent("Opening tunnel.");
|
|
|
- OpenTunnel();
|
|
|
- Log->AddSeparator();
|
|
|
+ ResetConnection();
|
|
|
+ FStatus = ssOpening;
|
|
|
|
|
|
- FSessionData->ConfigureTunnel(FTunnelLocalPortNumber);
|
|
|
-
|
|
|
- DoInformation(LoadStr(USING_TUNNEL), false);
|
|
|
- LogEvent(FORMAT("Connecting via tunnel interface %s:%d.",
|
|
|
- (FSessionData->HostName, FSessionData->PortNumber)));
|
|
|
- }
|
|
|
- else
|
|
|
+ try
|
|
|
{
|
|
|
- assert(FTunnelLocalPortNumber == 0);
|
|
|
- }
|
|
|
+ if (FFileSystem == NULL)
|
|
|
+ {
|
|
|
+ Log->AddStartupInfo();
|
|
|
+ }
|
|
|
|
|
|
- if (FFileSystem == NULL)
|
|
|
- {
|
|
|
- if (SessionData->FSProtocol == fsFTP)
|
|
|
+ assert(FTunnel == NULL);
|
|
|
+ if (FSessionData->Tunnel)
|
|
|
{
|
|
|
- #ifdef NO_FILEZILLA
|
|
|
- LogEvent("FTP protocol is not supported by this build.");
|
|
|
- FatalError(NULL, LoadStr(FTP_UNSUPPORTED));
|
|
|
- #else
|
|
|
- FFSProtocol = cfsFTP;
|
|
|
- FFileSystem = new TFTPFileSystem(this);
|
|
|
- FFileSystem->Open();
|
|
|
+ DoInformation(LoadStr(OPEN_TUNNEL), true);
|
|
|
+ LogEvent("Opening tunnel.");
|
|
|
+ OpenTunnel();
|
|
|
Log->AddSeparator();
|
|
|
- LogEvent("Using FTP protocol.");
|
|
|
- #endif
|
|
|
+
|
|
|
+ FSessionData->ConfigureTunnel(FTunnelLocalPortNumber);
|
|
|
+
|
|
|
+ DoInformation(LoadStr(USING_TUNNEL), false);
|
|
|
+ LogEvent(FORMAT("Connecting via tunnel interface %s:%d.",
|
|
|
+ (FSessionData->HostName, FSessionData->PortNumber)));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- assert(FSecureShell == NULL);
|
|
|
- try
|
|
|
+ assert(FTunnelLocalPortNumber == 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (FFileSystem == NULL)
|
|
|
+ {
|
|
|
+ if (SessionData->FSProtocol == fsFTP)
|
|
|
{
|
|
|
- FSecureShell = new TSecureShell(this, FSessionData, Log, Configuration);
|
|
|
+ #ifdef NO_FILEZILLA
|
|
|
+ LogEvent("FTP protocol is not supported by this build.");
|
|
|
+ FatalError(NULL, LoadStr(FTP_UNSUPPORTED));
|
|
|
+ #else
|
|
|
+ FFSProtocol = cfsFTP;
|
|
|
+ FFileSystem = new TFTPFileSystem(this);
|
|
|
+ FFileSystem->Open();
|
|
|
+ Log->AddSeparator();
|
|
|
+ LogEvent("Using FTP protocol.");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ assert(FSecureShell == NULL);
|
|
|
try
|
|
|
{
|
|
|
- FSecureShell->Open();
|
|
|
- }
|
|
|
- catch(Exception & E)
|
|
|
- {
|
|
|
- assert(!FSecureShell->Active);
|
|
|
- if (!FSecureShell->Active && !FTunnelError.IsEmpty())
|
|
|
+ FSecureShell = new TSecureShell(this, FSessionData, Log, Configuration);
|
|
|
+ try
|
|
|
{
|
|
|
- // the only case where we expect this to happen
|
|
|
- assert(E.Message == LoadStr(UNEXPECTED_CLOSE_ERROR));
|
|
|
- FatalError(&E, FMTLOAD(TUNNEL_ERROR, (FTunnelError)));
|
|
|
+ FSecureShell->Open();
|
|
|
}
|
|
|
- else
|
|
|
+ catch(Exception & E)
|
|
|
{
|
|
|
- throw;
|
|
|
+ assert(!FSecureShell->Active);
|
|
|
+ if (!FSecureShell->Active && !FTunnelError.IsEmpty())
|
|
|
+ {
|
|
|
+ // the only case where we expect this to happen
|
|
|
+ assert(E.Message == LoadStr(UNEXPECTED_CLOSE_ERROR));
|
|
|
+ FatalError(&E, FMTLOAD(TUNNEL_ERROR, (FTunnelError)));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Log->AddSeparator();
|
|
|
+ Log->AddSeparator();
|
|
|
|
|
|
- if ((SessionData->FSProtocol == fsSCPonly) ||
|
|
|
- (SessionData->FSProtocol == fsSFTP && FSecureShell->SshFallbackCmd()))
|
|
|
- {
|
|
|
- FFSProtocol = cfsSCP;
|
|
|
- FFileSystem = new TSCPFileSystem(this, FSecureShell);
|
|
|
- FSecureShell = NULL; // ownership passed
|
|
|
- LogEvent("Using SCP protocol.");
|
|
|
+ if ((SessionData->FSProtocol == fsSCPonly) ||
|
|
|
+ (SessionData->FSProtocol == fsSFTP && FSecureShell->SshFallbackCmd()))
|
|
|
+ {
|
|
|
+ FFSProtocol = cfsSCP;
|
|
|
+ FFileSystem = new TSCPFileSystem(this, FSecureShell);
|
|
|
+ FSecureShell = NULL; // ownership passed
|
|
|
+ LogEvent("Using SCP protocol.");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FFSProtocol = cfsSFTP;
|
|
|
+ FFileSystem = new TSFTPFileSystem(this, FSecureShell);
|
|
|
+ FSecureShell = NULL; // ownership passed
|
|
|
+ LogEvent("Using SFTP protocol.");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ __finally
|
|
|
{
|
|
|
- FFSProtocol = cfsSFTP;
|
|
|
- FFileSystem = new TSFTPFileSystem(this, FSecureShell);
|
|
|
- FSecureShell = NULL; // ownership passed
|
|
|
- LogEvent("Using SFTP protocol.");
|
|
|
+ delete FSecureShell;
|
|
|
+ FSecureShell = NULL;
|
|
|
}
|
|
|
}
|
|
|
- __finally
|
|
|
- {
|
|
|
- delete FSecureShell;
|
|
|
- FSecureShell = NULL;
|
|
|
- }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FFileSystem->Open();
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ __finally
|
|
|
{
|
|
|
- FFileSystem->Open();
|
|
|
+ if (FSessionData->Tunnel)
|
|
|
+ {
|
|
|
+ FSessionData->RollbackTunnel();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- __finally
|
|
|
- {
|
|
|
- if (FSessionData->Tunnel)
|
|
|
+
|
|
|
+ if (SessionData->CacheDirectoryChanges)
|
|
|
{
|
|
|
- FSessionData->RollbackTunnel();
|
|
|
+ assert(FDirectoryChangesCache == NULL);
|
|
|
+ FDirectoryChangesCache = new TRemoteDirectoryChangesCache();
|
|
|
+ if (SessionData->PreserveDirectoryChanges)
|
|
|
+ {
|
|
|
+ Configuration->LoadDirectoryChangesCache(SessionData->SessionKey,
|
|
|
+ FDirectoryChangesCache);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (SessionData->CacheDirectoryChanges)
|
|
|
+ DoStartup();
|
|
|
+
|
|
|
+ DoInformation(LoadStr(STATUS_READY), true);
|
|
|
+ FStatus = ssOpened;
|
|
|
+ }
|
|
|
+ catch(...)
|
|
|
{
|
|
|
- assert(FDirectoryChangesCache == NULL);
|
|
|
- FDirectoryChangesCache = new TRemoteDirectoryChangesCache();
|
|
|
- if (SessionData->PreserveDirectoryChanges)
|
|
|
+ // rollback
|
|
|
+ if (FDirectoryChangesCache != NULL)
|
|
|
{
|
|
|
- Configuration->LoadDirectoryChangesCache(SessionData->SessionKey,
|
|
|
- FDirectoryChangesCache);
|
|
|
+ delete FDirectoryChangesCache;
|
|
|
+ FDirectoryChangesCache = NULL;
|
|
|
}
|
|
|
+ throw;
|
|
|
}
|
|
|
-
|
|
|
- DoStartup();
|
|
|
-
|
|
|
- DoInformation(LoadStr(STATUS_READY), true);
|
|
|
- FStatus = ssOpened;
|
|
|
}
|
|
|
- catch(...)
|
|
|
+ __finally
|
|
|
{
|
|
|
- // rollback
|
|
|
- if (FDirectoryChangesCache != NULL)
|
|
|
+ // Prevent calling Information with active=false unless there was at least
|
|
|
+ // one call with active=true
|
|
|
+ if (FAnyInformation)
|
|
|
{
|
|
|
- delete FDirectoryChangesCache;
|
|
|
- FDirectoryChangesCache = NULL;
|
|
|
+ DoInformation("", true, false);
|
|
|
}
|
|
|
- throw;
|
|
|
}
|
|
|
}
|
|
|
- __finally
|
|
|
+ catch(EFatal &)
|
|
|
{
|
|
|
- // Prevent calling Information with active=false unless there was at least
|
|
|
- // one call with active=true
|
|
|
- if (FAnyInformation)
|
|
|
- {
|
|
|
- DoInformation("", true, false);
|
|
|
- }
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ catch(Exception & E)
|
|
|
+ {
|
|
|
+ // any exception while opening session is fatal
|
|
|
+ FatalError(&E, "");
|
|
|
}
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|