I won’t say much nonsense, I will just post java code to you.
import java.io.IOException;import sun.net.TelnetInputStream;import sun.net.ftp.FtpClient;public class MyFtp {static FtpClient myFtp;static String hostname;static String username;static String password;/*** @author cutelion 20051108 14:27* @param args*/public static void main(String[] args) {try {hostname = "203.171.236.123";myFtp = new FtpClient(hostname);myFtp.login("user", "pass");myFtp.binary();showFileContents();} catch (IOException e1) {System.out.print(e1);}}public static void showFileContents() {int ch;StringBuffer buf = new StringBuffer();try {TelnetInputStream inStream = myFtp.list();while ((ch = inStream.read()) >= 0) {buf.append((char) ch);}System.out.print(new String(buf.toString().getBytes("iso-8859-1"),"GBK"));inStream.close();myFtp.closeServer();} catch (Exception e) {System.out.println("Error" + e);}}}[@more@]Below are some control commands provided by the FtpClient class.
public void cd(String remoteDirectory)
This command is used to switch the directory on the remote system to the directory specified by the parameter remoteDirectory.
public void cdUp(): This command is used to switch directories on the remote system to the previous directory.
public String pwd(): This command displays the directory status on the remote system.
public void binary(): This command can set the transmission format to binary format.
public void ascii(): This command can set the transmission protocol to ASCII code format.
public void rename(String string, String string1)
This command can rename directories or files on the remote system.
In addition to the above methods, the class FtpClient also provides several methods that can be used to pass and retrieve directory manifests and files. These methods return input and output streams that can be read or written. Here are some of these main methods.
public TelnetInputStream list()
Returns the input stream corresponding to the current directory on the remote machine.
public TelnetInputStream get(String filename)
Get the filename on the remote machine and transfer the file to the local area with the help of TelnetInputStream.
public TelnetOutputStream put(String filename)
Open an output stream in a write manner through which the filename is transferred to the remote computer.