0

I have to upload and download a file using FTP server but I am facing issues in it. Have gone though many solutions but nothing seems to be working.

I am using secureftp-test.com as the testing FTP server.

Below is the code for uploading where in I am using FTPClient storeFile method but it doesn't seems to work.

public static void main(String[] args) {
    String server = "ftp.secureftp-test.com";
    int port = 21;
    String user = "test";
    String pass = "test";

    FTPClient ftpClient = new FTPClient();
    try {

        ftpClient.connect(server, port);
        boolean login = ftpClient.login(user, pass);
        System.out.println("login " + login);
        ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        File firstLocalFile = new File("D:/jetty.pdf");

        String firstRemoteFile = "myfile.pdf";
        InputStream inputStream = new FileInputStream(firstLocalFile);

        System.out.println("Start uploading first file");
        boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
        inputStream.close();
        if (done) {
            System.out.println("The first file is uploaded successfully.");
        } else {
            System.out.println("upload failed");
        }

    } catch (IOException ex) {
        System.out.println("Error: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        try {
            if (ftpClient.isConnected()) {
                ftpClient.logout();
                ftpClient.disconnect();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Each time the output is "upload failed". I don't understand where i am wrong.

roger_that
  • 9,493
  • 18
  • 66
  • 102

1 Answers1

0

Your port is incorrect. It uses:

FTPS via Auth TLS/SSL and implicit FTP over SSL on port 990

Also, if you read the site carefully, upload is forbidden:

Chilkat provides this FTPS test account for anyone wishing to test secure FTP client functionality. You may connect to ftp.secureftp-test.com, login as "test" with password "test", and download any files present on the server. The "test" account may also retrieve directory listings. However, it is restricted from uploading files to the server.

Reference: secureftp-test.com

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • Thanks Shivan for pointing this out. Well is there any other ftp server for testing purpose which i could use just to perform a sample upload and download ? – roger_that Apr 15 '13 at 07:16
  • you can setup your own FTP server, e.g. by FileZilla FTP server ( Windows ) or vsFTPd ( Linux-based ) – Raptor Apr 15 '13 at 07:57