Peace be unto you.
1.
Download
Commons Net from
http://jakarta.apache.org/site/binindex.cgi
2. Write this code
import org.apache.commons.net.ftp.FTPClient;
import java.io.*;
import org.apache.commons.net.ftp.FTPReply;
public class FTPThis
{
public static void main(String [] args)
{
FTPClient ftp = new FTPClient();
try
{
String server = "members.google.com";
String username="mromarkhan";
String password="x9s23msd0m3";
int reply;
ftp.connect(server);
ftp.login(username, password);
System.out.println("Connected to " + server + ".");
System.out.print(ftp.getReplyString());
// After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
System.out.println("PWD: " + ftp.printWorkingDirectory());
FileInputStream inputstream = new FileInputStream("c:/windows/desktop/quran.html");
if(ftp.storeFile("quran.html",inputstream))
{
System.out.println("Was uploaded");
}
else
{
System.out.println("Not uploaded");
}
}
catch(IOException e)
{
if(ftp.isConnected())
{
try
{
ftp.disconnect();
}
catch(IOException f)
{
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
System.exit(1);
}
}
}
3.
Realize that
"The convention for all the FTP command methods
in FTPClient is such that they
either return a boolean value or
some other value. The boolean methods
return true on a successful completion
reply from the FTP server and false on
a reply resulting in an error condition or failure."
-
http://jakarta.apache.org/commons/net/apidocs/org/apache/commons/net/ftp/FTPClient.html
4. Run Show
javac -classpath "C:\downloads\commons-net-1.1.0\commons-net-1.1.0\commons-net-1.1.0.jar;." FTPThis.java
java -classpath "C:\downloads\commons-net-1.1.0\commons-net-1.1.0\commons-net-1.1.0.jar;." FTPThis
5. Produces
Connected to members.google.com.
230-User mromarkhan has group access to: httpd
230 OK. Current restricted directory is /
PWD: /
Was uploaded
Have a good day.