<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.twig.es/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=Source_for_the_ftp_download_client</id>
		<title>Source for the ftp download client - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=Source_for_the_ftp_download_client"/>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=Source_for_the_ftp_download_client&amp;action=history"/>
		<updated>2026-05-06T15:12:20Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.0</generator>

	<entry>
		<id>https://wiki.twig.es/index.php?title=Source_for_the_ftp_download_client&amp;diff=4580&amp;oldid=prev</id>
		<title>George2: Created page with &quot;&lt;source lang=&quot;java&quot;&gt;  import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; im...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=Source_for_the_ftp_download_client&amp;diff=4580&amp;oldid=prev"/>
				<updated>2020-01-26T09:05:48Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;  import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; im...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
 &lt;br /&gt;
import org.apache.commons.net.ftp.FTP;&lt;br /&gt;
import org.apache.commons.net.ftp.FTPClient;&lt;br /&gt;
 &lt;br /&gt;
/**&lt;br /&gt;
 * A program demonstrates how to upload files from local computer to a remote&lt;br /&gt;
 * FTP server using Apache Commons Net API.&lt;br /&gt;
 * @author www.codejava.net&lt;br /&gt;
 */&lt;br /&gt;
public class FTPDownloadFileDemo {&lt;br /&gt;
 &lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        String server = &amp;quot;localhost&amp;quot;;&lt;br /&gt;
        int port = 21;&lt;br /&gt;
        String user = &amp;quot;muppet&amp;quot;;&lt;br /&gt;
        String pass = &amp;quot;puppet&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
        FTPClient ftpClient = new FTPClient();&lt;br /&gt;
        try {&lt;br /&gt;
 &lt;br /&gt;
            ftpClient.connect(server, port);&lt;br /&gt;
            ftpClient.login(user, pass);&lt;br /&gt;
            ftpClient.enterLocalPassiveMode();&lt;br /&gt;
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);&lt;br /&gt;
 &lt;br /&gt;
            // APPROACH #1: using retrieveFile(String, OutputStream)&lt;br /&gt;
            String remoteFile1 = &amp;quot;testfile&amp;quot;;&lt;br /&gt;
            File downloadFile1 = new File(&amp;quot;/home/george2/testfile&amp;quot;);&lt;br /&gt;
            OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));&lt;br /&gt;
            boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);&lt;br /&gt;
            outputStream1.close();&lt;br /&gt;
 &lt;br /&gt;
            if (success) {&lt;br /&gt;
                System.out.println(&amp;quot;File #1 has been downloaded successfully.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
 &lt;br /&gt;
            // APPROACH #2: using InputStream retrieveFileStream(String)&lt;br /&gt;
            String remoteFile2 = &amp;quot;song.mp3&amp;quot;;&lt;br /&gt;
            File downloadFile2 = new File(&amp;quot;/home/george2/song.mp3&amp;quot;);&lt;br /&gt;
            OutputStream outputStream2 = new BufferedOutputStream(new FileOutputStream(downloadFile2));&lt;br /&gt;
            InputStream inputStream = ftpClient.retrieveFileStream(remoteFile2);&lt;br /&gt;
            byte[] bytesArray = new byte[4096];&lt;br /&gt;
            int bytesRead = -1;&lt;br /&gt;
            while ((bytesRead = inputStream.read(bytesArray)) != -1) {&lt;br /&gt;
                outputStream2.write(bytesArray, 0, bytesRead);&lt;br /&gt;
            }&lt;br /&gt;
 &lt;br /&gt;
            success = ftpClient.completePendingCommand();&lt;br /&gt;
            if (success) {&lt;br /&gt;
                System.out.println(&amp;quot;File #2 has been downloaded successfully.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            outputStream2.close();&lt;br /&gt;
            inputStream.close();&lt;br /&gt;
 &lt;br /&gt;
        } catch (IOException ex) {&lt;br /&gt;
            System.out.println(&amp;quot;Error: &amp;quot; + ex.getMessage());&lt;br /&gt;
            ex.printStackTrace();&lt;br /&gt;
        } finally {&lt;br /&gt;
            try {&lt;br /&gt;
                if (ftpClient.isConnected()) {&lt;br /&gt;
                    ftpClient.logout();&lt;br /&gt;
                    ftpClient.disconnect();&lt;br /&gt;
                }&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                ex.printStackTrace();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>George2</name></author>	</entry>

	</feed>