Ho trovato questa classe su Internet:
Nella funzione sendLine() però le due istruzioni * non vengono riconosciute.codice:import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.Socket; public class FTPClient { private BufferedReader reader=null; private BufferedReader writer=null; private Socket socket=null; private static boolean DEBUG = false; public FTPClient() { } /** * Connects to an FTP server and logs in with the supplied username * and password. */ public synchronized void connect(String host, int port, String user, String pass) throws IOException { if (socket != null) { throw new IOException("Socket is already connected. Disconnect first."); }else socket = new Socket(host, port); reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); String response = readLine(); if (!response.startsWith("220 ")) { throw new IOException("FTPClient received an unknown response when connecting to the FTP server: " + response); } sendLine("USER " + user); response = readLine(); if (!response.startsWith("331 ")) { throw new IOException("FTPClient received an unknown response after sending the user: " + response); } sendLine("PASS " + pass); response = readLine(); if (!response.startsWith("230 ")) { throw new IOException("FTPClient was unable to log in with the supplied password: " + response); } // Now logged in. } private void sendLine(String line) throws IOException { if (socket == null) { throw new IOException("FTPClient is not connected."); } try { * writer.write(line + "\r\n"); * writer.flush(); if (DEBUG) { System.out.println("> " + line); } } catch (IOException e) { socket = null; throw e; } } private String readLine() throws IOException { String line = reader.readLine(); if (DEBUG) { System.out.println("< " + line); } return line; } public synchronized boolean bin() throws IOException { sendLine("TYPE I"); String response = readLine(); return (response.startsWith("200 ")); } public synchronized boolean ascii() throws IOException { sendLine("TYPE A"); String response = readLine(); return (response.startsWith("200 ")); } }
Qualcuno può aiutarmi?
tulipan

Rispondi quotando