欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java 上传文件到ftp服务器,javaftp,package cn.o

来源: javaer 分享于  点击 4269 次 点评:2

java 上传文件到ftp服务器,javaftp,package cn.o


package cn.outofmemory.snippets.core;import org.apache.commons.net.ftp.FTPClient;import java.io.FileInputStream;import java.io.IOException;public class FtpFileUpload {    public static void main(String[] args) {        FTPClient client = new FTPClient();        FileInputStream fis = null;        try {            client.connect("ftp.javacodegeeks.com");            client.login("username", "password");            // Create an InputStream of the file to be uploaded            String filename = "test.txt";            fis = new FileInputStream(filename);            // Store file on server and logout            client.storeFile(filename, fis);            client.logout();        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                if (fis != null) {                    fis.close();                }                client.disconnect();            } catch (IOException e) {                e.printStackTrace();            }        }    }}

更多帮助参考这里

相关栏目:

用户点评