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"); if (ftpClient.isConnected()) { } } catch (Exception e) { e.printStackTrace(); } } } import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class FTPExample { public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try { String localFilePath = "path/to/local/file.txt"; String remoteDirectory = "path/to/remote/directory"; ftpClient.setFileType(FTP.BINARY_FILE_TYPE); File localFile = new File(localFilePath); FileInputStream inputStream = new FileInputStream(localFile); ftpClient.storeFile(remoteDirectory + "/" + localFile.getName(), inputStream); } catch (Exception e) { e.printStackTrace(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } } import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class FTPExample { public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try { String localDirectory = "path/to/local/directory"; String remoteFilePath = "path/to/remote/file.txt"; ftpClient.setFileType(FTP.BINARY_FILE_TYPE); OutputStream outputStream = new FileOutputStream(localDirectory + "/file.txt"); ftpClient.retrieveFile(remoteFilePath, outputStream); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } }


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