diff --git a/src/FTPCache.cpp b/src/FTPCache.cpp index 6e1199b..3612a44 100644 --- a/src/FTPCache.cpp +++ b/src/FTPCache.cpp @@ -25,7 +25,8 @@ const char * FTPCache::CacheElem = "Cache"; const int PathCacheSize = MAX_PATH+10; //paths generally do not exceed MAX_PATH, but if it happens often buffer reallocation may need some profiling (e.g. set ceiling instead of just allocating) FTPCache::FTPCache() : - m_cacheParent(NULL) + m_cacheParent(NULL), + m_activePort(0) { m_activeHost = SU::DupString(TEXT("")); m_activeUser = SU::DupString(TEXT("")); @@ -42,12 +43,13 @@ int FTPCache::SetCacheParent(FTPCache * cacheParent) { return 0; } -int FTPCache::SetEnvironment(const char * host, const char * user) { +int FTPCache::SetEnvironment(const char * host, const char * user, int port) { SU::FreeTChar(m_activeHost); SU::FreeTChar(m_activeUser); m_activeHost = SU::Utf8ToTChar(host); m_activeUser = SU::Utf8ToTChar(user); + m_activePort = port; ExpandPaths(); @@ -331,6 +333,8 @@ TCHAR* FTPCache::ExpandPath(const TCHAR * path) { } replacestring = SU::ReplaceString(replacestring, TEXT("%USERNAME%"), m_activeUser); replacestring = SU::ReplaceString(replacestring, TEXT("%HOSTNAME%"), m_activeHost); + tstring port = std::to_wstring(m_activePort); + replacestring = SU::ReplaceString(replacestring, TEXT("%PORT%"), port); TCHAR * expanded = new TCHAR[MAX_PATH]; BOOL res = PathSearchAndQualify(replacestring.c_str(), expanded, MAX_PATH); diff --git a/src/FTPCache.h b/src/FTPCache.h index 6d7b8d0..52e7b0d 100644 --- a/src/FTPCache.h +++ b/src/FTPCache.h @@ -35,7 +35,7 @@ class FTPCache { virtual ~FTPCache(); virtual int SetCacheParent(FTPCache * m_cacheParent); - virtual int SetEnvironment(const char * host, const char * user); + virtual int SetEnvironment(const char * host, const char * user, int port); virtual const PathMap & GetPathMap(int i) const; virtual int GetPathMapCount() const; @@ -67,6 +67,7 @@ class FTPCache { TCHAR* m_activeHost; TCHAR* m_activeUser; + int m_activePort; }; #endif //FTPCACHE_H diff --git a/src/FTPProfile.cpp b/src/FTPProfile.cpp index 289cdbd..13a753c 100644 --- a/src/FTPProfile.cpp +++ b/src/FTPProfile.cpp @@ -78,7 +78,7 @@ FTPProfile::FTPProfile(const TCHAR * name) : m_keyFile = SU::DupString(TEXT("")); m_passphrase = SU::strdup(""); - m_cache->SetEnvironment(m_hostname, m_username); + m_cache->SetEnvironment(m_hostname, m_username, m_port); } FTPProfile::FTPProfile(const TCHAR * name, const FTPProfile* other) : @@ -108,7 +108,7 @@ FTPProfile::FTPProfile(const TCHAR * name, const FTPProfile* other) : m_keyFile = SU::DupString(other->m_keyFile); m_passphrase = SU::strdup(other->m_passphrase); - m_cache->SetEnvironment(m_hostname, m_username); + m_cache->SetEnvironment(m_hostname, m_username, m_port); for(int i = 0; i < other->m_cache->GetPathMapCount(); i++) { PathMap map; @@ -262,7 +262,7 @@ int FTPProfile::SetParent(const TCHAR * parent) { int FTPProfile::SetHostname(const char * hostname) { SU::free(m_hostname); m_hostname = SU::strdup(hostname); - m_cache->SetEnvironment(m_hostname, m_username); + m_cache->SetEnvironment(m_hostname, m_username, m_port); return 0; } @@ -274,6 +274,7 @@ int FTPProfile::SetPort(int port) { if (port <= 0 || port >= 65536) return -1; m_port = port; + m_cache->SetEnvironment(m_hostname, m_username, m_port); return 0; } @@ -284,7 +285,7 @@ const char* FTPProfile::GetUsername() const { int FTPProfile::SetUsername(const char * username) { SU::free(m_username); m_username = SU::strdup(username); - m_cache->SetEnvironment(m_hostname, m_username); + m_cache->SetEnvironment(m_hostname, m_username, m_port); return 0; } diff --git a/src/FTPSession.cpp b/src/FTPSession.cpp index 4cbdd67..14198d6 100644 --- a/src/FTPSession.cpp +++ b/src/FTPSession.cpp @@ -86,7 +86,7 @@ int FTPSession::StartSession(FTPProfile * sessionProfile) { m_currentProfile = sessionProfile; m_currentProfile->AddRef(); - m_ftpSettings->GetGlobalCache()->SetEnvironment(m_currentProfile->GetHostname(), m_currentProfile->GetUsername()); + m_ftpSettings->GetGlobalCache()->SetEnvironment(m_currentProfile->GetHostname(), m_currentProfile->GetUsername(), m_currentProfile->GetPort()); m_mainWrapper = m_currentProfile->CreateWrapper(); if (m_mainWrapper == NULL) { diff --git a/src/FTPSettings.cpp b/src/FTPSettings.cpp index cb8f5b7..60e40ad 100644 --- a/src/FTPSettings.cpp +++ b/src/FTPSettings.cpp @@ -48,7 +48,7 @@ const TCHAR* FTPSettings::GetGlobalCachePath() const { int FTPSettings::SetGlobalCachePath(const TCHAR * path) { if (!path || lstrlen(path) < 4) { //must at least have a drive designator or network name - path = TEXT("%CONFIGDIR%\\Cache\\%USERNAME%@%HOSTNAME%"); + path = TEXT("%CONFIGDIR%\\Cache\\%USERNAME%@%HOSTNAME%\\%PORT%"); } PathMap globalPathmap;