sendtobranch.java
来自「ftp上传下载,支持续传,使用swing组件」· Java 代码 · 共 44 行
JAVA
44 行
package com.test;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
public class SendToBranch {
public static void sendFile() throws IOException {
int ch;
String hostname = "192.168.1.87";// 要登录主机的IP地址
int port = 21;// 要登录主机的FTP端口号
String user = "efly";// 用户名
String pass = "efly";// 密码
FtpClient aftp = new FtpClient(hostname, port);
aftp.login(user, pass);
aftp.ascii();
System.out.println("登录成功");
File localFile = new File("C:/WINDOWS/Web/Wallpaper/Vista_黑夜精灵.jpg");// 本地文件路径
RandomAccessFile sendFile = new RandomAccessFile(localFile, "r");
sendFile.seek(0);
TelnetOutputStream tos = aftp.put("f:/ourfiles/文档/hujing.jpg");// 上传文件
DataOutputStream dos = new DataOutputStream(tos);
while (sendFile.getFilePointer() < sendFile.length()) {
ch = sendFile.read();
dos.write(ch);
}
tos.close();
sendFile.close();
System.out.println("上传文件完毕");
}
public static void main(String[] args) {
try {
sendFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?