上传文件到ftp服务器java代码

2015-02-26 0 853
上传文件到ftp服务器java代码
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();
            }
        }
    }
}

遇见资源网 java 上传文件到ftp服务器java代码 http://www.ox520.com/8810.html

JDBC的工具类
下一篇: JDBC的工具类
常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务