import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; public class FTPExample { public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try { ftpClient.connect("ftp.example.com", 21); ftpClient.login("username", "password"); ftpClient.logout(); ftpClient.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import java.io.*; public class FTPExample { public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try { ftpClient.connect("ftp.example.com", 21); ftpClient.login("username", "password"); File localFile = new File("localfile.txt"); InputStream inputStream = new FileInputStream(localFile); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.storeFile("remotefile.txt", inputStream); inputStream.close(); OutputStream outputStream = new FileOutputStream("localfile.txt"); ftpClient.retrieveFile("remotefile.txt", outputStream); outputStream.close(); ftpClient.logout(); ftpClient.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } catch (ConnectException e) { } catch (SocketException e) { } catch (IOException e) { e.printStackTrace(); } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); }


上一篇:
下一篇:
切换中文