@Test
public void testFtpClient() throws SocketException, IOException
{
//创建FtpClient对象
FTPClient ftpClient = new FTPClient();
//创建连接
ftpClient.connect("192.168.0.105", 21);
//登录ftp
ftpClient.login("ftpuser", "ppc123456");
System.out.println(ftpClient);
//上传文件
FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\ppc\\Desktop\\hello.png"));
System.out.println(inputStream);
//文件类型
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);//图片无法查看
//設置為被動模式
ftpClient.enterLocalPassiveMode(); //图片为空
ftpClient.changeWorkingDirectory("/home/ftpuser/www/image");
ftpClient.storeFile("hello7.png", inputStream);
//close
ftpClient.logout();
}
public void testFtpClient() throws SocketException, IOException
{
//创建FtpClient对象
FTPClient ftpClient = new FTPClient();
//创建连接
ftpClient.connect("192.168.0.105", 21);
//登录ftp
ftpClient.login("ftpuser", "ppc123456");
System.out.println(ftpClient);
//上传文件
FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\ppc\\Desktop\\hello.png"));
System.out.println(inputStream);
//文件类型
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);//图片无法查看
//設置為被動模式
ftpClient.enterLocalPassiveMode(); //图片为空
ftpClient.changeWorkingDirectory("/home/ftpuser/www/image");
ftpClient.storeFile("hello7.png", inputStream);
//close
ftpClient.logout();
}