首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

使用JAVA API下传文件到FTP服务器

2012-09-21 
使用JAVA API上传文件到FTP服务器?private void FtpUpload() throws IOException {??String ftpServer

使用JAVA API上传文件到FTP服务器

?private void FtpUpload() throws IOException {
??String ftpServer = "ftp server ip address";
??String username = "username";
??String password = "password";
??String filename = "filename";
??String path = "/path";
??FtpClient ftpClient = new FtpClient();
??ftpClient.openServer(ftpServer);
??ftpClient.login(username, password);
??ftpClient.binary();
??TelnetOutputStream os = ftpClient.put(filename);// 服务器上保存的文件名
??InputStream is = new FileInputStream("/path");// 本地文件路径
??byte[] bytes = new byte[1048576];
??int c;
??while ((c = is.read(bytes)) != -1) {
???os.write(bytes, 0, c);
??}
??os.close();
??ftpClient.closeServer();
?}

热点排行