javaftpweb的简单介绍

博主:adminadmin 2023-01-28 23:09:14 402

今天给各位分享javaftpweb的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎样用java开发ftp客户端

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.List;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.*;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JList;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextField;

import javax.swing.JToolBar;

import javax.swing.DefaultListModel;

import javax.swing.JTree;

import sun.net.TelnetInputStream;

import sun.net.;

import sun.net.;

public class Ttt

extends JFrame

implements ActionListener {

FtpClient ftp = null;

private List list = new List();

private JPanel FtpClientFrame = new JPanel(new BorderLayout());

private JPanel FtpClientFrameOne = new JPanel(new FlowLayout(FlowLayout.

LEFT));

private JPanel FtpClientFrameTwo = new JPanel(new GridLayout(1, 8));

private JPanel FtpClientFrameThree = new JPanel(new GridLayout(2, 1));

private JPanel FtpClientFrameFour = new JPanel(new GridLayout(1, 2));

//连接、断开按钮

private JButton linkButton = new JButton("Link");

private JButton breakButton = new JButton("Break");

//连接状态

private JLabel statusLabel = new JLabel();

//用户登录

private JLabel urlLabel = new JLabel("Ftp URL:");

private JLabel usernameLabel = new JLabel("username:");

private JLabel passwordLabel = new JLabel("password:");

private JLabel portLabel = new JLabel("port:");

private JTextField urlTextField = new JTextField(10);

private JTextField usernameTextField = new JTextField(10);

private JTextField passwordTextField = new JTextField(10);

private JTextField portTextField = new JTextField(10);

//本地、远程窗口

DefaultListModel modelList = new DefaultListModel();

private JList localList = new JList();

private JList distanceList = new JList();

JScrollPane localScrollPane = new JScrollPane(localList);

JScrollPane distanceScrollPane = new JScrollPane(distanceList);

//本地、远程目录树

private JTree localTree;

private JTree ServerTree;

public Ttt() {

FtpClientFrameOne.add(linkButton);

FtpClientFrameOne.add(breakButton);

FtpClientFrameOne.add(statusLabel);

FtpClientFrameTwo.add(urlLabel);

FtpClientFrameTwo.add(urlTextField);

FtpClientFrameTwo.add(usernameLabel);

FtpClientFrameTwo.add(usernameTextField);

FtpClientFrameTwo.add(passwordLabel);

FtpClientFrameTwo.add(passwordTextField);

FtpClientFrameTwo.add(portLabel);

FtpClientFrameTwo.add(portTextField);

FtpClientFrameThree.add(FtpClientFrameOne);

FtpClientFrameThree.add(FtpClientFrameTwo);

FtpClientFrameFour.add(localScrollPane);

FtpClientFrameFour.add(list);

FtpClientFrame.add(FtpClientFrameThree, "North");

FtpClientFrame.add(FtpClientFrameFour, "Center");

setContentPane(FtpClientFrame);

setTitle("Ftp客户端");

setSize(600, 500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

linkButton.addActionListener(this);

breakButton.addActionListener(this);

}

public String getDir(String path) {

String dirName;

int ch;

int begin = 55;

dirName = path.substring(begin).trim();

return dirName;

}

public void loadList() {

StringBuffer buf = new StringBuffer();

int ch;

list.removeAll();

try {

TelnetInputStream t = ;

t.setStickyCRLF(true);

while ( (ch = t.read()) = 0) {

if (ch == '\n') {

list.add(getDir(buf.toString()));

buf.setLength(0);

}

else {

buf.append( (char) ch);

}

}

}

catch (IOException e) {

e.printStackTrace();

}

list.validate();

}

public void actionPerformed(ActionEvent evt) {

Object source = evt.getSource();

if (source == linkButton) {

//连接Ftp服务器

try {

if (ftp != null)

;

statusLabel.setText("连接中,请等待.....");

ftp = new FtpClient(urlTextField.getText());

(usernameTextField.getText(),

passwordTextField.getText());

;

}

catch (FtpLoginException e) {

JOptionPane.showMessageDialog(null, "Login Failure!!!");

e.printStackTrace();

}

catch (IOException e) {

JOptionPane.showMessageDialog(null,

urlTextField.getText() + "Connection Failure!!!");

e.printStackTrace();

}

catch (SecurityException e) {

JOptionPane.showMessageDialog(null, "No Purview!!!");

e.printStackTrace();

}

if (urlTextField.getText().equals(""))

JOptionPane.showMessageDialog(null, "Ftp服务器地址不能空!!!");

else if (usernameTextField.getText().equals(""))

JOptionPane.showMessageDialog(null, "用户名不能为空!!!");

else if (passwordTextField.getText().equals(""))

JOptionPane.showMessageDialog(null, "密码不能为空!!!");

else

statusLabel.setText("已连接到Ftp:" + urlTextField.getText());

loadList();

}

if (source == breakButton) {

System.exit(0);

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

Ttt ftpClientFrame = new Ttt();

}

}

收集的一些代码,忘记从拿来的了` 你可以看看

java web 大文件上传下载

直接把大文件读取为IO流,之后进行上传下载即可,不用担心文件大,是可以分流下载上传的(setBufferSize(1024))。

举例:

import hkrt.b2b.view.util.Log;

import hkrt.b2b.view.util.ViewUtil;

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import org.apache.commons.net.;

import org.apache.commons.net.;

public class CCFCCBFTP {

/**

* 上传文件

*

* @param fileName

* @param plainFilePath 明文文件路径路径

* @param filepath

* @return

* @throws Exception

*/

public static String fileUploadByFtp(String plainFilePath, String fileName, String filepath) throws Exception {

FileInputStream fis = null;

ByteArrayOutputStream bos = null;

FTPClient ftpClient = new FTPClient();

String bl = "false";

try {

fis = new FileInputStream(plainFilePath);

bos = new ByteArrayOutputStream(fis.available());

byte[] buffer = new byte[1024];

int count = 0;

while ((count = fis.read(buffer)) != -1) {

bos.write(buffer, 0, count);

}

bos.flush();

Log.info("加密上传文件开始");

Log.info("连接远程上传服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);

ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);

ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);

FTPFile[] fs;

fs = ftpClient.listFiles();

for (FTPFile ff : fs) {

if (ff.getName().equals(filepath)) {

bl="true";

ftpClient.changeWorkingDirectory("/"+filepath+"");

}

}

Log.info("检查文件路径是否存在:/"+filepath);

if("false".equals(bl)){

ViewUtil.dataSEErrorPerformedCommon( "查询文件路径不存在:"+"/"+filepath);

return bl;

}

ftpClient.setBufferSize(1024);

ftpClient.setControlEncoding("GBK");

// 设置文件类型(二进制)

ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

ftpClient.storeFile(fileName, fis);

Log.info("上传文件成功:"+fileName+"。文件保存路径:"+"/"+filepath+"/");

return bl;

} catch (Exception e) {

throw e;

} finally {

if (fis != null) {

try {

fis.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (bos != null) {

try {

bos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

}

}

/**

*下载文件

*

* @param localFilePath

* @param fileName

* @param routeFilepath

* @return

* @throws Exception

*/

public static String fileDownloadByFtp(String localFilePath, String fileName,String routeFilepath) throws Exception {

FileInputStream fis = null;

ByteArrayOutputStream bos = null;

FileOutputStream fos = null;

FTPClient ftpClient = new FTPClient();

String SFP = System.getProperty("file.separator");

String bl = "false";

try {

Log.info("下载并解密文件开始");

Log.info("连接远程下载服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);

ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);

ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);

// ftpClient.connect(CMBCUtil.CMBCHOSTNAME, 2021);

// ftpClient.login(CMBCUtil.CMBCLOGINNAME, CMBCUtil.CMBCLOGINPASSWORD);

FTPFile[] fs;

ftpClient.makeDirectory(routeFilepath);

ftpClient.changeWorkingDirectory(routeFilepath);

bl = "false";

fs = ftpClient.listFiles();

for (FTPFile ff : fs) {

if (ff.getName().equals(fileName)) {

bl = "true";

Log.info("下载文件开始。");

ftpClient.setBufferSize(1024);

// 设置文件类型(二进制)

ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

InputStream is = ftpClient.retrieveFileStream(fileName);

bos = new ByteArrayOutputStream(is.available());

byte[] buffer = new byte[1024];

int count = 0;

while ((count = is.read(buffer)) != -1) {

bos.write(buffer, 0, count);

}

bos.flush();

fos = new FileOutputStream(localFilePath+SFP+fileName);

fos.write(bos.toByteArray());

Log.info("下载文件结束:"+localFilePath);

}

}

Log.info("检查文件是否存:"+fileName+" "+bl);

if("false".equals(bl)){

ViewUtil.dataSEErrorPerformedCommon("查询无结果,请稍后再查询。");

return bl;

}

return bl;

} catch (Exception e) {

throw e;

} finally {

if (fis != null) {

try {

fis.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (bos != null) {

try {

bos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (fos != null) {

try {

fos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

}

}}

备注:以上方法就实现了流的二进制上传下载转换,只需要将服务器连接部分调整为本地的实际ftp服务用户名和密码即可。

如何在电脑上建立一个视频服务器,然后通过手机无需下载可以直接在线观看

装个Air Playit,它 支持 iOS 与 Android,能将320种不同的视频和音频文件通过 Wi-Fi、3G网络远程无线地传送到你的 iPhone、iPad 或是安卓手机上面去并直接流畅地实时播放,无需转换视频格式和等待!该软件能把你的电脑变成一个云端服务器。Air Playit 的使用需要你在电脑上安装服务器端(支持 Windows 与 Mac),然后再在移动设备上安装客户端 (支持 iOS 与 Android),目前它们均是免费软件!

javaWeb能和ftp实现大文件上传吗

java上传可以使用common-fileupload上传组件的。common-fileupload是jakarta项目组开发的一个功能很强大的上传文件组件下面先介绍上传文件到服务器(多文件上传):import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.util.regex.*;

import org.apache.commons.fileupload.*;

public class upload extends HttpServlet {

private static final String CONTENT_TYPE = "text/html; charset=GB2312";

//Process the HTTP Post request

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType(CONTENT_TYPE);

PrintWriter out=response.getWriter();

try {

DiskFileUpload fu = new DiskFileUpload();

// 设置允许用户上传文件大小,单位:字节,这里设为2m

fu.setSizeMax(2*1024*1024);

// 设置最多只允许在内存中存储的数据,单位:字节

fu.setSizeThreshold(4096);

// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录

fu.setRepositoryPath("c:\\windows\\temp");

//开始读取上传信息

List fileItems = fu.parseRequest(request);

// 依次处理每个上传的文件

Iterator iter = fileItems.iterator();//正则匹配,过滤路径取文件名

String regExp=".+\\\\(.+)$";//过滤掉的文件类型

String[] errorType={".exe",".com",".cgi",".asp"};

Pattern p = Pattern.compile(regExp);

while (iter.hasNext()) {

FileItem item = (FileItem)iter.next();

//忽略其他不是文件域的所有表单信息

if (!item.isFormField()) {

String name = item.getName();

long size = item.getSize();

if((name==null||name.equals("")) size==0)

continue;

Matcher m = p.matcher(name);

boolean result = m.find();

if (result){

for (int temp=0;temp if (m.group(1).endsWith(errorType[temp])){

throw new IOException(name+": wrong type");

}

}

try{//保存上传的文件到指定的目录//在下文中上传文件至数据库时,将对这里改写

item.write(new File("d:\\" + m.group(1))); out.print(name+" "+size+"

");

}

catch(Exception e){

out.println(e);

} }

else

{

throw new IOException("fail to upload");

}

}

}

}

catch (IOException e){

out.println(e);

}

catch (FileUploadException e){

out.println(e);

}

}

}

JavaWeb SpringMVC项目使用xml配置方式发布,打开浏览器访问变成文件目录类似ftp,折中情况如何解决?

Tomcat中conf\Catalina\localhost目录下,发布的配置文件改成: docBase="D:\workspaces\workspaces\web\WebRoot" 试试。

阿里云部署javaweb项目 rt,所有环境已经配好,jdk tomcat mysql。 ftp

直接在服务器上访问127.0.0.1能进项目吗?还有就是tamcat启动时有没有报错呢?

关于javaftpweb和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。