简体   繁体   中英

File not getting downloaded from ftp

Code:

import java.io.FileOutputStream; import org.apache.commons.net.ftp.FTPClient;

public class FtpDownloader {

    // Server Credentials
    String host = "ip";
    String username = "user";
    String password = "pass";

    public static void main(String args[]) {
        new FtpDownloader().downloadFile();
    }

    public void downloadFile() {
        try {
            FTPClient client_ftp = new FTPClient();
            FileOutputStream fos = null;

            client_ftp.connect(host);
            client_ftp.login(username, password);

            System.out.println("Connected : " + client_ftp.isConnected());

            fos = new FileOutputStream("d://update_mac.txt");

            Boolean file_got = client_ftp.retrieveFile("/update/update_mac.txt", fos);

            System.out.println("Downloaded : " + file_got);

            fos.close();

            client_ftp.disconnect();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

As you can see am trying to download a file from the ftp server but When i run the code the connection is established but the file doesn't get downloaded it shows 0kb on my system.What you think the reason may be?

Thanks in advance

Be sure to use one of these parameter-combinations for your connect() method call:

void    connect(InetAddress host)
void    connect(InetAddress host, int port)
void    connect(InetAddress host, int port, InetAddress localAddr, int localPort)
void    connect(String hostname)
void    connect(String hostname, int port)
void    connect(String hostname, int port, InetAddress localAddr, int localPort)

You might have tried connect("127.0.0.1") which is not one of these combinations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM