📄 ouf.java
字号:
package com.test;
import java.io.IOException;
import sun.net.ftp.FtpClient;
public class OUF {
static String filepath;
public static FtpClient login() {
System.out.println("ftp登录成功");
FtpClient aftp = null;
try {
String hostname = "192.168.1.87";// 要登录主机的IP地址
int port = 21;// 要登录主机的FTP端口号
String user = "efly";// 用户名
String pass = "efly";// 密码
aftp = new FtpClient(hostname, port);
aftp.login(user, pass);
aftp.ascii();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("ok");
return aftp;
}
// public static List getNameList(FtpClient aftp) throws IOException {
// BufferedReader dr = new BufferedReader(new InputStreamReader(aftp
// .nameList("f:/ourfiles/文档/")));
// List al = new ArrayList();
// String s = "";
// while ((s = dr.readLine()) != null) {
// al.add(s);
// }
// dr.close();
// return al;
// }
@SuppressWarnings("unchecked")
public static void mulu(FtpClient aftp){
try {
String cmd = "";
aftp.sendServer(cmd);
aftp.readServerResponse();
String a = aftp.getResponseString();
System.out.println(a);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
FtpClient aftp;
try {
aftp = OUF.sendFile();
OUF.mulu(aftp);
} catch (IOException e) {
e.printStackTrace();
}
}
public static FtpClient sendFile() throws IOException {
// long fileSize = 0;
// String ftpname = "";
// boolean isExists = false;
System.out.println("ftp登录成功");
FtpClient aftp = null;
String hostname = "192.168.1.87";// 要登录主机的IP地址
int port = 21;// 要登录主机的FTP端口号
String user = "efly";// 用户名
String pass = "efly";// 密码
aftp = new FtpClient(hostname, port);
aftp.login(user, pass);
System.out.println(aftp.getResponseString());
aftp.ascii();
return aftp;
// int ch;
// Test t = new Test();
// List list = t.filename();
// for (int i = 0; i < list.size(); i++) {
// List a = getNameList(aftp);
// File localFile = new File("d:\\files\\" + list.get(i));// 本地文件路径
// String filepath = (String) list.get(i);
// for (int j = 0; j < a.size(); j++) {
// ftpname = (String) a.get(j);
// if (filepath.equals(ftpname)) {
// fileSize = localFile.length();
// isExists = true;
// break;
// }
// }
// if (isExists) {
// // aftp.cd("f:/ourfiles/文档/");
// // String cmd = "DELE " + ftpname + "\r\n";
// // System.out.println("ftp删除成功!");
// // aftp.sendServer(cmd);
// // aftp.readServerResponse();
// aftp.cd("f:/ourfiles/文档/");
// String cmd = "APPE" + ftpname + "\r\n";
// System.out.println("向ftp发送续传命令!");
// aftp.sendServer(cmd);
// aftp.readServerResponse();
// RandomAccessFile sendFile = new RandomAccessFile(localFile,
// "rw");
// sendFile.seek(fileSize);
// TelnetOutputStream tos = aftp.put("f:/ourfiles/文档/"
// + list.get(i));// 上传文件
// DataOutputStream dos = new DataOutputStream(tos);
// while (sendFile.getFilePointer() < sendFile.length()) {
// ch = sendFile.read();
// dos.write(ch);
// }
// tos.close();
// sendFile.close();
// System.out.println("上传文件完毕");
// File file = new File("d:\\files\\" + list.get(i));
// file.delete();
// System.out.println("上传成功并且删除");
// dos.close();
// tos.close();
// sendFile.close();
// System.out.println("资源关闭");
//
// } else {
// RandomAccessFile sendFile = new RandomAccessFile(localFile,
// "rw");
// sendFile.seek(0);
// TelnetOutputStream tos = aftp.put("f:/ourfiles/文档/"
// + list.get(i));// 上传文件
// DataOutputStream dos = new DataOutputStream(tos);
// while (sendFile.getFilePointer() < sendFile.length()) {
// ch = sendFile.read();
// dos.write(ch);
// }
// tos.close();
// sendFile.close();
// System.out.println("上传文件完毕");
// File file = new File("d:\\files\\" + list.get(i));
// file.delete();
// System.out.println("上传成功并且删除");
// dos.close();
// tos.close();
// sendFile.close();
// System.out.println("资源关闭");
// }
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -