Documente Academic
Documente Profesional
Documente Cultură
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.connectors.HTTPTunnelConnector;
import java.io.*;
// if(mode == 1) {
// directory = args[8];
// }
/* try
{
// Create a new file output stream
// connected to "myfile.txt"
out = new FileOutputStream("myfile.txt");
p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}*/
try {
if (!connecting.exists() ) {
connecting.createNewFile();
}
test.connect(ftpServer, ftpPort);
if (!connected.exists() ) {
-1-
D:\Documents\TestFTP.java Tuesday, November 02, 2010 15:52
//connecting.delete();
connected.createNewFile();
}
System.out.println("Tidak dapat terhubung dengan FTP server, koneksi gagal atau kesalahan kombinasi
username/password");
System.exit(0);
}
try {
if (!login.exists() ) {
//connected.delete();
login.createNewFile();
}
test.login(username,password);
}catch (Exception e) {
e.printStackTrace();
System.out.println("Tidak dapat terhubung dengan FTP server, koneksi gagal");
System.exit(0);
}
// if (mode ==1) {
try {
test.changeDirectory(directory);
System.out.println("current dir 2 = "+ test.currentDirectory());
} catch (Exception e){
e.printStackTrace();
System.out.println("Gagal untuk pindah direktori");
}
// }
try {
if(!uploading.exists()) {
//login.delete();
uploading.createNewFile();
}
//test.upload(new java.io.File(fileName));
test.upload(f1);
if(!uploaded.exists()) {
//uploading.delete();
uploaded.createNewFile();
}
String[] files = test.listNames();
for (int i=0 ; i<files.length ; i++) {
System.out.println("file "+(i+1)+" = "+files[i]);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Upload gagal");
try {
//test.disconnect(true);
}catch (Exception c) {
c.printStackTrace();
System.out.println("Gagal memutuskan koneksi");
}
System.exit(0);
}
try {
if(!disconnecting.exists()) {
//uploaded.delete();
-2-
D:\Documents\TestFTP.java Tuesday, November 02, 2010 15:52
disconnecting.createNewFile();
}
test.disconnect(true);
if(!disconnected.exists()) {
//disconnecting.delete();
disconnected.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Gagal memutuskan koneksi");
}
System.exit(0);
}
}
-3-