使用edtftpj实现ftp上传一例,够简单!
package ftp.test;
import java.io.File;
import java.io.IOException;
import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FileTransferClient;
public class FtpTest {
public static void main(String[] argv) {
FileTransferClient ftp = null ;
//ftp服务器地址
String hostname = "16.158.50.173" ;
//ftp端口
int port = 21 ;
//ftp登录名
String username = "xxxx" ;
//ftp登录密码
String password = "xxxx" ;
ftp = new FileTransferClient() ;
try {
//设置上传参数
ftp.setRemoteHost(hostname) ;
ftp.setRemotePort(port) ;
ftp.setUserName(username) ;
ftp.setPassword(password) ;
ftp.setContentType(FTPTransferType.BINARY) ;
//连接到ftp服务器
ftp.connect() ;
ftp.uploadFile("D:/111.csv", "/111.csv") ;
} catch (FTPException e) {
System.out.println("set up ftp connection failed") ;
e.printStackTrace();
}
catch(IOException e)
{
System.out.println("set up ftp connection failed") ;
}
finally
{
if(ftp != null)
{
try {
ftp.disconnect() ;
} catch (FTPException e) {
System.out.println("close up ftp connection failed") ;
e.printStackTrace();
} catch (IOException e) {
System.out.println("close up ftp connection failed") ;
e.printStackTrace();
}
}
}
}
}