Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FTP file download problem

656336May 29 2008 — edited Jan 13 2009
i have the following code:
/*import org.apache.commons.net.ftp.*;
import com.jscape.inet.ftp.*;
import java.net.*;
public class FTPDownload {
	public static void main(String[] args) {
		Ftp ftp=new Ftp("ftp.myserver.com","jsmith","secret");
		ftp.connect();
		ftp.download(arg0);
		// Eventually other operations here ...
		ftpclient.disconnect();
		

	}

}*/
import com.jscape.inet.ftp.*;
import java.io.*;
import java.util.Enumeration;

public class FTPDownload extends FtpAdapter {
    public static void main(String[] args) {
        try {
        	Ftp ftp=new Ftp("ftp://194.44.214.3","",""); //stabilim conexiunea
            ftp.connect(); //ne conectam
            String listing=ftp.getDirListingAsString(); //listam directoarele de pe FTP-ul curent
            System.out.println(listing+"\n");
            Enumeration files=ftp.getDirListing();
            while(files.hasMoreElements())
            {
            	FtpFile file=(FtpFile)files.nextElement();
            	if(file.isDirectory())
            	{
            		System.out.println(file.getFilename());
            	}
            }
            ftp.setLocalDir(new File("C:/tmp")); //directorul unde se salveaza fisierele
            ftp.setDir("temp"); //setez directorul curent de pe FTP; by default, acesta este directorul asignat la prima logare pe FTP
            //ftp.setAscii(); //in special doar pentru fisiere text 
            ftp.setBinary(); //setez modul ASCII pentru imagini, executabile...
            ftp.download("test.txt"); //downloadeaza fisierul din directorul curent de pe FTP, si il salveaza fisierul in directorul local setat
            //ftp.upload(new File("c:/tmp/test.txt")); //pentru uploadare fisier
            ftp.disconnect();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
but at the runtime i got an exception, and i don't know why, that ftp exists and i wanna download a file.
but before, i perform a listing of existing directories.
what's wrong?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2009
Added on May 29 2008
26 comments
1,893 views