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

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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();
            }
        }
    }
}