Java implementation FTP download file

zhaozj2021-02-16  81

For example, to download ftp://ftp.xx.com/index.html:

Import Sun.Net.ftp.ftpclient; Import Java.io. *; Import Sun.Net. *;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2004 *

Company: * @ Author petehero * @version 1.0 * /

Public class ftpdown {

Public ftpdown () {

} Public static void main (string [] args) {try {ftpclient fc = new ftpclient ("ftp.xx.com"); fc.login ("UserName", "888888"); int Ch; file fi = new file ("c: //index.html"); randomaccessfile getfile = new randomaccessfile (FI, "RW"); getFile.seek (0); telnetinputstream fget = fc.get ("index.html"); DataInputStream Puts = New DataInputStream (FGET); while ((ch = puts.read ())> = 0) {getfile.write (ch);} fget.close (); getFile.close (); fc.closeserver ();} catch IOEXCEPTION EX) {

EX.PrintStackTrace ();

}

If the file is in a certain directory, add fc.cd ("foodir");

转载请注明原文地址:https://www.9cbs.com/read-13796.html

New Post(0)