MCPcopy Create free account
hub / github.com/Driver-C/tryssh / tryCopyWithoutCache

Method tryCopyWithoutCache

pkg/control/scp.go:104–140  ·  view source on GitHub ↗
(user string)

Source from the content-addressed store, hash-verified

102}
103
104func (cc *ScpController) tryCopyWithoutCache(user string) {
105 combinations := config.GenerateCombination(cc.destIP, user, cc.configuration)
106 launchers := launcher.NewScpLaunchersByCombinations(combinations, cc.source, cc.destination,
107 cc.recursive, cc.sshTimeout)
108 connectors := make([]launcher.Connector, len(launchers))
109 for i, l := range launchers {
110 connectors[i] = l
111 }
112 hitLaunchers := ConcurrencyTryToConnect(cc.concurrency, connectors)
113 if len(hitLaunchers) > 0 {
114 utils.Infoln("Login succeeded. The cache will be added.")
115 hitLauncher := hitLaunchers[0].(*launcher.ScpLauncher)
116 newServerCache := launcher.GetConfigFromSSHConnector(&hitLauncher.SSHConnector)
117 if cc.cacheIsFound {
118 newServerCache.Alias = cc.configuration.ServerLists[cc.cacheIndex].Alias
119 utils.Infoln("The old cache will be deleted.")
120 cc.configuration.ServerLists = append(
121 cc.configuration.ServerLists[:cc.cacheIndex], cc.configuration.ServerLists[cc.cacheIndex+1:]...)
122 }
123 cc.configuration.ServerLists = append(cc.configuration.ServerLists, *newServerCache)
124 if err := config.UpdateConfig(cc.configuration); err == nil {
125 utils.Infoln("Cache added.")
126 if cc.sshTimeout > sshClientTimeoutWhenLogin {
127 hitLauncher.SSHTimeout = cc.sshTimeout
128 } else {
129 hitLauncher.SSHTimeout = sshClientTimeoutWhenLogin
130 }
131 if !hitLauncher.Launch() {
132 utils.Errorf("Login failed.\n")
133 }
134 } else {
135 utils.Errorf("Cache added failed.\n\n")
136 }
137 } else {
138 utils.Errorf("There is no password combination that can log in.\n")
139 }
140}
141
142// NewScpController creates a new ScpController for the given source, destination, and configuration.
143func NewScpController(source string, destination string, configuration *config.MainConfig) *ScpController {

Callers 2

TryCopyMethod · 0.95
tryCopyWithCacheMethod · 0.95

Calls 8

GenerateCombinationFunction · 0.92
InfolnFunction · 0.92
UpdateConfigFunction · 0.92
ErrorfFunction · 0.92
ConcurrencyTryToConnectFunction · 0.85
LaunchMethod · 0.65

Tested by

no test coverage detected