import sun.net.ftp.FtpClient;
import sun.net.ftp.FtpProtocolException;
import sun.net.ftp.impl.DefaultFtpClientProvider;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
public static void main(String[] args) throws IOException, FtpProtocolException {
// 连接 登录
FtpClient ftpClient = DefaultFtpClientProvider.provider().createFtpClient();
ftpClient.connect(new InetSocketAddress("192.168.130.200", 21));
ftpClient.login("yourname", "yourpass".toCharArray());
// 列出当前用户的工作目录
String workingDirectory = ftpClient.getWorkingDirectory();
System.out.println("working directory:" + workingDirectory);
// 下载 到本地
String outputFile = "D:\\work\\config.json";
// ftp当前用户工作目录下的文件名
ftpClient.getFile("config.json", new FileOutputStream(outputFile));
// 上传
String uploadFile = "D:\\work\\readme.txt";
// 指定ftp工作目录还不够,必须要指定到文件名
ftpClient.putFile(workingDirectory + "/readme.txt", new FileInputStream(uploadFile));
}