📄 sendtobranch.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -