Professional Documents
Culture Documents
FTP uses for transferring files between ftp Client and ftp Server. It is most easiest way to
transfering files between computers (FTP Client and Ftp Server).A basic FTP connection
need a remote computer (the Ftpclient) calling an FTP server. FTP client used to download
content from the server.
1 We have need to Login ftp server with configured username and password to gain access
to the Remote System.
3 Specified a remote server directory path that uses download files from the server.
Sample Code for Downloading files to local computer from the ftp Server :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
ftpClient.connect(serverAddress, port);
ftpClient.login(username,password);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE/FTP.ASCII_FILE_TYPE);
String remoteFilePath = "/filename.txt";
File localfile = new File("E:/ftpServerFile.txt");
OutputStream outputStream = new BufferedOutputStream(new
FileOutputStream(localfile));
boolean success = ftpClient.retrieveFile(remoteFilePath, outputStream);
outputStream.close();
if (success) {
System.out.println("Ftp file successfully download.");
}