/** * Open a URLConnection on the given URL. */ @Override protected URLConnection openConnection(URL u) throws IOException { return new FtpURLConnection(u); }
private void connectInternal() throws IOException { int port = url.getPort(); int connectTimeout = getConnectTimeout(); if (port <= 0) { port = FTP_PORT; ctrlOutput = controlSocket.getOutputStream(); ctrlInput = controlSocket.getInputStream(); login(); setType(); if (!getDoInput()) { cd(); port(); if (connectTimeout == 0) { acceptSocket.setSoTimeout(getConnectTimeout()); if (getDoInput()) { getFile(); } else { sendFile(); dataSocket.setSoTimeout(getReadTimeout()); acceptSocket.close(); } catch (InterruptedIOException e) { throw new IOException("Could not establish data connection"); if (getDoInput()) { inputStream = new FtpURLInputStream( new BufferedInputStream(dataSocket.getInputStream()), controlSocket);
/** * Creates a input stream for writing to this URL Connection. * * @return The input stream to write to * @throws IOException * Cannot read from URL or error creating InputStream * * @see #getContent() * @see #getOutputStream() * @see java.io.InputStream * @see java.io.IOException * */ @Override public InputStream getInputStream() throws IOException { if (!connected) { connect(); } return inputStream; }
/** * Returns the content type of the resource. Just takes a guess based on the * name. */ @Override public String getContentType() { String result = guessContentTypeFromName(url.getFile()); if (result == null) { return "content/unknown"; } return result; }
connectInternal(); } else { ProxySelector selector = ProxySelector.getDefault(); currentProxy = iter.next(); try { connectInternal(); connectOK = true; } catch (IOException ioe) {
private void getFile() throws IOException { int reply; String file = url.getFile(); write("RETR " + file + "\r\n"); reply = getReply(); if (reply == FTP_NOTFOUND && file.length() > 0 && file.charAt(0) == '/') { write("RETR " + file.substring(1) + "\r\n"); reply = getReply(); } if (!(reply == FTP_OPENDATA || reply == FTP_TRANSFEROK)) { throw new FileNotFoundException("Unable to retrieve file: " + reply); } }
/** * Returns the content type of the resource. Just takes a guess based on the * name. */ @Override public String getContentType() { String result = guessContentTypeFromName(url.getFile()); if (result == null) { return "content/unknown"; } return result; }
connectInternal(); } else { ProxySelector selector = ProxySelector.getDefault(); currentProxy = iter.next(); try { connectInternal(); connectOK = true; } catch (IOException ioe) {
private void connectInternal() throws IOException { int port = url.getPort(); int connectTimeout = getConnectTimeout(); if (port <= 0) { port = FTP_PORT; ctrlOutput = controlSocket.getOutputStream(); ctrlInput = controlSocket.getInputStream(); login(); setType(); if (!getDoInput()) { cd(); port(); if (connectTimeout == 0) { acceptSocket.setSoTimeout(getConnectTimeout()); if (getDoInput()) { getFile(); } else { sendFile(); dataSocket.setSoTimeout(getReadTimeout()); acceptSocket.close(); } catch (InterruptedIOException e) { throw new IOException("Could not establish data connection"); if (getDoInput()) { inputStream = new FtpURLInputStream( new BufferedInputStream(dataSocket.getInputStream()), controlSocket);
/** * Returns a connection, which is established via the <code>proxy</code>, * to the FTP server specified by this <code>URL</code>. If * <code>proxy</code> is DIRECT type, the connection is made in normal * way. * * @param url * the URL which the connection is pointing to * @param proxy * the proxy which is used to make the connection * @return a connection to the resource pointed by this url. * * @throws IOException * if this handler fails to establish a connection. * @throws IllegalArgumentException * if any argument is null or the type of proxy is wrong. * @throws UnsupportedOperationException * if the protocol handler doesn't support this method. */ @Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { if (url == null || proxy == null) { throw new IllegalArgumentException("url == null || proxy == null"); } return new FtpURLConnection(url, proxy); }
/** * Creates a output stream for writing to this URL Connection. * * @return The output stream to write to * @throws IOException * when the OutputStream could not be created * * @see #getContent() * @see #getInputStream() * @see java.io.IOException * */ @Override public OutputStream getOutputStream() throws IOException { if (!connected) { connect(); } return dataSocket.getOutputStream(); }
/** * Returns the content type of the resource. Just takes a guess based on the * name. */ @Override public String getContentType() { String result = guessContentTypeFromName(url.getFile()); if (result == null) { return "content/unknown"; } return result; }
connectInternal(); } else { ProxySelector selector = ProxySelector.getDefault(); currentProxy = iter.next(); try { connectInternal(); connectOK = true; } catch (IOException ioe) {
private void connectInternal() throws IOException { int port = url.getPort(); int connectTimeout = getConnectTimeout(); if (port <= 0) { port = FTP_PORT; ctrlOutput = controlSocket.getOutputStream(); ctrlInput = controlSocket.getInputStream(); login(); setType(); if (!getDoInput()) { cd(); port(); if (connectTimeout == 0) { acceptSocket.setSoTimeout(getConnectTimeout()); if (getDoInput()) { getFile(); } else { sendFile(); dataSocket.setSoTimeout(getReadTimeout()); acceptSocket.close(); } catch (InterruptedIOException e) { throw new IOException("Could not establish data connection"); if (getDoInput()) { inputStream = new FtpURLInputStream( new BufferedInputStream(dataSocket.getInputStream()), controlSocket);
private void login() throws IOException { int reply; reply = getReply(); if (reply == FTP_USERREADY) { } else { throw new IOException("Unable to connect to server: " + url.getHost()); } write("USER " + username + "\r\n"); reply = getReply(); if (reply == FTP_PASWD || reply == FTP_LOGGEDIN) { } else { throw new IOException("Unable to log in to server (USER): " + url.getHost()); } if (reply == FTP_PASWD) { write("PASS " + password + "\r\n"); reply = getReply(); if (!(reply == FTP_OK || reply == FTP_USERREADY || reply == FTP_LOGGEDIN)) { throw new IOException("Unable to log in to server (PASS): " + url.getHost()); } } }
/** * Open a URLConnection on the given URL. */ @Override protected URLConnection openConnection(URL u) throws IOException { return new FtpURLConnection(u); }
/** * Creates a input stream for writing to this URL Connection. * * @return The input stream to write to * @throws IOException * Cannot read from URL or error creating InputStream * * @see #getContent() * @see #getOutputStream() * @see java.io.InputStream * @see java.io.IOException * */ @Override public InputStream getInputStream() throws IOException { if (!connected) { connect(); } return inputStream; }
/** * Returns the content type of the resource. Just takes a guess based on the * name. */ @Override public String getContentType() { String result = guessContentTypeFromName(url.getFile()); if (result == null) { return "content/unknown"; } return result; }