import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.Iterator;
import sun.net.ftp.FtpDirEntry;
/**
sunjdk自带的FTPCleint工具类,速度快,稳定
*/
public class SunFTPTest {
public static void main(String[] args) throws Exception {
sun.net.ftp.FtpClient client = sun.net.ftp.FtpClient.create();
System.out.println(client);
client.connect(new InetSocketAddress("192.168.198.100", 21));
client.login("ftpuser", "654321".toCharArray());
client.changeDirectory("/home/ftpuser/www");
System.out.println(client.getWorkingDirectory());
Iterator<FtpDirEntry> entries = client.listFiles("/home/ftpuser/www");
//设置为被动模式
client.enablePassiveMode(true);
while (entries.hasNext()) {
FtpDirEntry entry = entries.next();
System.out.println(entry.getName());
}
//设置传输类型为二进制
client.setType(sun.net.ftp.FtpClient.TransferType.BINARY);
// InputStream inputStream = new FileInputStream("D:/111.txt");
InputStream inputStream = new FileInputStream("D:/222.aiv");
client.appendFile("myFile.file", inputStream);
client.close();
}
}
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.Iterator;
import sun.net.ftp.FtpDirEntry;
/**
sunjdk自带的FTPCleint工具类,速度快,稳定
*/
public class SunFTPTest {
public static void main(String[] args) throws Exception {
sun.net.ftp.FtpClient client = sun.net.ftp.FtpClient.create();
System.out.println(client);
client.connect(new InetSocketAddress("192.168.198.100", 21));
client.login("ftpuser", "654321".toCharArray());
client.changeDirectory("/home/ftpuser/www");
System.out.println(client.getWorkingDirectory());
Iterator<FtpDirEntry> entries = client.listFiles("/home/ftpuser/www");
//设置为被动模式
client.enablePassiveMode(true);
while (entries.hasNext()) {
FtpDirEntry entry = entries.next();
System.out.println(entry.getName());
}
//设置传输类型为二进制
client.setType(sun.net.ftp.FtpClient.TransferType.BINARY);
// InputStream inputStream = new FileInputStream("D:/111.txt");
InputStream inputStream = new FileInputStream("D:/222.aiv");
client.appendFile("myFile.file", inputStream);
client.close();
}
}