• 大小: 15KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-12
  • 语言: Java
  • 标签: Java、FTP  

资源简介

网络环境中的一项基本应用就是将文件从一台计算机中复制到另一台可能相距很远的计算机中。而文件传送协议FTP是因特网上使用得最广泛的文件传送协议。FTP使用客户服务器方式。 设计要求: 1) 以命令行形式运行 2) 该FTP客户端程序具有以下基本功能:能完成FTP链接的打开和关闭操作;能执行文件的上传和下载;能完成目录的创建、删除等有关操作。要求可以传输简单的文本文件。

资源截图

代码片段和文件信息

package cn.edu.scau.cmi.edwincheng.ftpServer;


import java.text.SimpleDateFormat;
import java.util.Scanner;

import com.enterprisedt.net.ftp.FileTransferClient;

public class Client {

/**
 * 代码示例
 * 
 * FileTransferClient ftpClient =
 * FTPUnit.getFileTransferClient(“192.168.1.254“21“ftp““123456“);
 * FileInputStream fis = new FileInputStream(new File(“D:\\ip.log“));
 * FileTransferOutputStream ftos = ftpClient.uploadStream(“/test/ip.log“);
 * byte[] bytes = new byte[1024]; int c; while ((c = fis.read(bytes)) != -1)
 * { ftos.write(bytes 0 c); } ftos.flush(); ftos.close(); fis.close();
 * 
 * @throws IOException 
 * @throws FTPException 
 * 
 */

public static SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss“);
public static java.util.Date time = new java.util.Date();

public static void main(String[] args) throws Exception {
int option;
boolean runFlag = true;
Scanner input = new Scanner(System.in);

//ftp类
FileTransferClient ftpClient = null ;

while (runFlag) {

showmenu();
option = input.nextInt();

switch (option) {
case 1:
//如果检测到已经连接,返回ture  不再重新连接
if(checkFtpConnetion(ftpClient)){
break;
}else {
// System.out.println(“输入ftp地址:“);
// String url = input.next();
//
// System.out.println(“请输入端口号,默认21:“);
// int port = input.nextInt();
//
// System.out.println(“输入用户名:“);
// String username = input.next();
//
// System.out.println(“输入密码:“);
// String password = input.next();
//
// ftpClient = FtpUtil.getFileTransferClient(url username password port);

ftpClient = FtpUtil.getFileTransferClient(“10.211.55.5“ “private“ “private“ 21);

// ftpClient = FtpUtil.getFileTransferClient(“172.26.14.35“ “upload“ “upload“ 21);

}
break;

case 2:
ftpClient=FtpUtil.closeFileTransferClient(ftpClient);

break;

case 3:
System.out.println(“输入本地文件路径:“);
String localFilePath = input.next();
System.out.println(“输入远程文件夹名字“);
String folderPath = input.next();
System.out.println(“输入远程文件名“);
String remoteFileName = input.next();
FtpUtil.upload(localFilePath remoteFileName folderPath ftpClient);

System.out.println(“上传成功“);

break;

case 4:
System.out.println(“请输入下载文件路径:“);
String remoteFilePath = input.next();

System.out.println(“请输入本地文件路径:“);
localFilePath = input.next();

FtpUtil.download(localFilePath remoteFilePath ftpClient);

break;

case 5:
System.out.println(“请输入创建目录的路径:“);
folderPath = input.next();
FtpUtil.createDirectory(ftpClient folderPath);

break;

case 6:
System.out.println(“请输入删除类型:1、文件  2、文件夹“);
int type = input.nextInt();
System.out.println(“请输入要删除的路径:“);
String remotePaths = input.next();
FtpUtil.delete(remotePaths type ftpClient);

break;

case 7:
boolean flag = true;
while (flag) {

System.out.println(“请输入字

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-09 20:57  FTPClient\
     文件         414  2017-04-25 22:51  FTPClient\.classpath
     文件         368  2017-04-25 17:28  FTPClient\.project
     目录           0  2017-04-25 22:51  FTPClient\.settings\
     文件         587  2017-04-25 22:50  FTPClient\.settings\org.eclipse.jdt.core.prefs
     目录           0  2017-04-25 22:51  FTPClient\bin\
     目录           0  2017-04-25 22:51  FTPClient\bin\cn\
     目录           0  2017-04-25 22:51  FTPClient\bin\cn\edu\
     目录           0  2017-04-25 22:51  FTPClient\bin\cn\edu\scau\
     目录           0  2017-04-25 22:51  FTPClient\bin\cn\edu\scau\cmi\
     目录           0  2017-04-25 22:51  FTPClient\bin\cn\edu\scau\cmi\edwincheng\
     目录           0  2017-04-25 23:27  FTPClient\bin\cn\edu\scau\cmi\edwincheng\ftpServer\
     文件        5875  2017-05-02 00:42  FTPClient\bin\cn\edu\scau\cmi\edwincheng\ftpServer\Client.class
     文件        5266  2017-05-02 12:59  FTPClient\bin\cn\edu\scau\cmi\edwincheng\ftpServer\FtpUtil.class
     文件         514  2017-05-02 13:11  FTPClient\README.txt
     目录           0  2017-09-09 20:57  __MACOSX\
     目录           0  2017-09-09 20:57  __MACOSX\FTPClient\
     文件         632  2017-05-02 13:11  __MACOSX\FTPClient\._README.txt
     目录           0  2017-04-25 17:29  FTPClient\src\
     目录           0  2017-04-25 17:29  FTPClient\src\cn\
     目录           0  2017-04-25 17:29  FTPClient\src\cn\edu\
     目录           0  2017-04-25 17:29  FTPClient\src\cn\edu\scau\
     目录           0  2017-04-25 17:29  FTPClient\src\cn\edu\scau\cmi\
     目录           0  2017-04-25 17:29  FTPClient\src\cn\edu\scau\cmi\edwincheng\
     目录           0  2017-04-25 23:27  FTPClient\src\cn\edu\scau\cmi\edwincheng\ftpServer\
     文件        6883  2017-05-02 00:42  FTPClient\src\cn\edu\scau\cmi\edwincheng\ftpServer\Client.java
     文件        5506  2017-05-02 12:59  FTPClient\src\cn\edu\scau\cmi\edwincheng\ftpServer\FtpUtil.java

评论

共有 条评论

相关资源