11/*
22 * Copyright (c) 1995, 1996 Robert Gentleman and Ross Ihaka
33 * Copyright (c) 1997-2013, The R Core Team
4- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates
4+ * Copyright (c) 2017, 2021 , Oracle and/or its affiliates
55 *
66 * This program is free software; you can redistribute it and/or modify
77 * it under the terms of the GNU General Public License as published by
4848import com .oracle .truffle .r .runtime .context .RContext ;
4949import com .oracle .truffle .r .runtime .context .TruffleRLanguage ;
5050import java .io .OutputStream ;
51- import sun . net . www . protocol . ftp . FtpURLConnection ;
51+ import java . util . Locale ;
5252
5353/**
5454 * Support for the "internal"method of "utils::download.file". TODO take note of "quiet", "mode" and
@@ -72,11 +72,14 @@ public abstract class Download extends RExternalBuiltinNode.Arg6 {
7272 protected int download (String urlString , String destFile , boolean quiet , @ SuppressWarnings ("unused" ) String mode , @ SuppressWarnings ("unused" ) boolean cacheOK ,
7373 @ SuppressWarnings ("unused" ) Object headers ,
7474 @ CachedContext (TruffleRLanguage .class ) TruffleLanguage .ContextReference <RContext > ctxRef ) {
75+ String protocol ;
7576 try {
7677 String urlStr = urlString ;
7778 URLConnection con ;
7879 while (true ) {
79- con = new URL (urlStr ).openConnection ();
80+ URL url = new URL (urlStr );
81+ protocol = url .getProtocol ();
82+ con = url .openConnection ();
8083 if (con instanceof HttpURLConnection ) {
8184 HttpURLConnection httpCon = (HttpURLConnection ) con ;
8285 httpCon .setInstanceFollowRedirects (false );
@@ -124,7 +127,7 @@ protected int download(String urlString, String destFile, boolean quiet, @Suppre
124127 StdConnections .getStderr ().writeString (" length unknown" , true );
125128 }
126129 StdConnections .getStderr ().flush ();
127- } else if (con instanceof FtpURLConnection ) {
130+ } else if (protocol != null && protocol . toLowerCase ( Locale . ROOT ). equals ( "ftp" ) ) {
128131 if (len >= 0 ) {
129132 StdConnections .getStderr ().writeString (String .format (" ftp data connection made, file length %d bytes" , len ), true );
130133 } else {
0 commit comments