-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTPUpload.java
More file actions
53 lines (44 loc) · 1.59 KB
/
FTPUpload.java
File metadata and controls
53 lines (44 loc) · 1.59 KB
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
51
52
53
package getlinks;
/**
*
* @author thrasos
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;
public class FTPUpload {
public static void main(String args[]) throws IOException {
uploadFile();
}
public static boolean uploadFile() throws FileNotFoundException, IOException {
/* the name of the file you want to upload from the working direcory*/
String filename = "index.html";
System.out.println("FTP start for "+filename);
FTPClient client = new FTPClient();
/* enter your FTP credentials[host, username,password]
obviously its not ftp.example.com etc */
client.connect("FTP.EXAMPLE.COM");
client.login("USERNAME", "PASSWORD");
/*The Directory you want the file to be uploaded in my case it's the top folder.*/
client.changeWorkingDirectory("/");
/*Prints the current DIrectory you are in.*/
System.out.println("Current directory is " + client.printWorkingDirectory());
/*yes you need this*/
client.enterLocalPassiveMode();
/*get input stream*/
InputStream input;
input = new FileInputStream(filename);
/*store the file in the remote server*/
client.storeFile(filename, input);
/*close the stream*/
input.close();
/*logout*/
client.logout();
/*disconect from the host*/
client.disconnect();
System.out.println("Category Index Uploaded");
return true;
}
}