No more nonsense to say, directly to everyone to paste the Java code.
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) {
T ry {
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 @]
The following are some of the control commands provided by the FtpClient class.
public void CD (String remotedirectory)
This command switches 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 status of the directory on the remote system.
public void Binary (): This command sets the transport format to binary format.
public void ASCII (): This command sets the transport protocol to an ASCII format.
public void rename (String string,string string1)
This command renames a directory or file on a remote system.
In addition to the above methods, class FtpClient also provides several methods that can be used to pass and retrieve catalog listings and files. These methods return input and output streams that are available for reading or writing. Here are some of the main methods.
Public Telnetinputstream list ()
Returns the input stream corresponding to the current directory on the remote machine.
Public Telnetinputstream get (String filename)
Gets the file filename on the remote machine, using Telnetinputstream to transfer the file to the local.
Public Telnetoutputstream put (String filename)
Opens an output stream by writing to transmit file filename to the remote computer through this output stream.