FTP客户端的设计与实现
boolean uploadFile(String localFile, String targetFileName) 使用
TelnetOutputStream tos = null;
RandomAccessFile sendFile = null; DataOutputStream dos = null; try {
File file = new File(localFile);
sendFile = new RandomAccessFile(file, \ sendFile.seek(0);
tos = this.ftpClient.put(targetFileName); dos = new DataOutputStream(tos); int ch = 0;
while (sendFile.getFilePointer() < sendFile.length()) {
ch = sendFile.read(); dos.write(ch); }
获取文件输出流,读取数据并写入文件
(6) 下载文件
boolean downloadFile(String srcFileName, String targetFileName)
使用TelnetInputStream tis = null;
RandomAccessFile getFile = null; boolean result = true; try {
File file = new File(targetFileName);
getFile = new RandomAccessFile(file, \ getFile.seek(0);
tis = this.ftpClient.get(srcFileName);
DataInputStream dis = new DataInputStream(tis); int ch = 0; while (true) {
ch = dis.read(); if (ch < 0) {
break; }
getFile.write(ch) }
第 12 页 共 27 页
FTP客户端的设计与实现
getFile.close(); }
获取文件输入流,读取数据并写入文件
(7) 进入上一级文件目录 up()
使用ftpClient.cdUp();实现
(8) 进入下一级文件目录 downDir()
使用上面的方法来实现下一级文件目录的访问
(9) 给文件重命名
boolean renameFile(String oldName, String newName)
使用ftpClient.rename(oldName, newName);来实现
(10) 删除文件
deleteFile(String fileName)
使用String cmd = \ ftpClient.sendServer(cmd); 来实现
(11) 获取当前路径 String getDir()
使用return this.ftpClient.pwd();实现
(12) 关闭连接 String close()
使用ftpClient.closeServer();实现
第 13 页 共 27 页
FTP客户端的设计与实现
第四章 系统实现
——单连晖 陈智
4.1界面设计的实现 4.1.1连接服务器
单击连接若服务器名称、端口、用户名和密码对的前提下登录到指定的
服务器上面,弹出“登录成功”对话框,并在下方状态栏中显示“登录成功
4.1.2获取文件列表
第 14 页 共 27 页
FTP客户端的设计与实现
登录到服务器上面之后,获取在服务器用户的主文件及文件夹 并在下方状态栏显示
4.1.3断开服务器
当用户需要关闭连接时,单机“断开连接”就可断开与服务器的连接,在状态栏上显示“连接已断开”,此时并不退出客户端。
第 15 页 共 27 页
相关推荐: