Skip to content

Commit

Permalink
Replaced usage of uri.Hostname and uri.Port with an explicit split of…
Browse files Browse the repository at this point in the history
… ":" looking for the host/port in order to remain backwards-compatible with Go 1.7.
  • Loading branch information
arizvisa committed Feb 14, 2018
1 parent 74efe53 commit 2d83f31
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions common/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,20 +612,36 @@ func (d *FTPDownloader) Download(dst *os.File, src *url.URL) error {
}
uri := src

// Split the hostname and port from the net/url
uriHostnameComponents := strings.SplitN(uri.Host, ":", 2)
uriHostname := uriHostnameComponents[0]
uriPort := ""
if len(uriHostnameComponents) == 2 {
uriPort = uriHostnameComponents[1]
}

// add the default ftp port
if uri.Port() == "" {
if uriPort == "" {
port, err := net.LookupPort("ip4", "ftp")
if err != nil {
port = 21
}
uri.Host = fmt.Sprintf("%s:%d", uri.Hostname(), port)
uri.Host = fmt.Sprintf("%s:%d", uriHostname, port)
}

// Do it again after we fixed it up
uriHostnameComponents = strings.SplitN(uri.Host, ":", 2)
uriHostname = uriHostnameComponents[0]
uriPort = ""
if len(uriHostnameComponents) == 2 {
uriPort = uriHostnameComponents[1]
}

// connect to ftp server
var cli *ftp.ServerConn

log.Printf("Starting download over FTP: %s(:%s) -> %s\n", uri.Hostname(), uri.Port(), uri.Path)
cli, err := ftp.Dial(fmt.Sprintf("%s:%s", uri.Hostname(), uri.Port()))
log.Printf("Starting download over FTP: %s(:%s) -> %s\n", uriHostname, uriPort, uri.Path)
cli, err := ftp.Dial(fmt.Sprintf("%s:%s", uriHostname, uriPort))
if err != nil {
return err
}
Expand Down

0 comments on commit 2d83f31

Please sign in to comment.