Friday, March 25, 2011

utility for file transfer. It connects to the the FTP server, delete file, receive and put the file to the FTP server.


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.log4j.Logger;

public class SandvineFTP {

private Logger logger = Logger.getLogger(SandvineFTP.class);
private static SandvineFTP sFTP;
FTPClient client = new FTPClient();
// make singleton
private SandvineFTP(){
}
public static SandvineFTP getInstance(){
if(sFTP==null)
sFTP =  new SandvineFTP();
return sFTP; 
}
// make connection with the server...
public boolean getConnection(String serverName, String uName, String pwd){
boolean result=false;
try {
client.connect(serverName);
int code = client.getReplyCode();
if(FTPReply.isPositiveCompletion(code)){
logger.info("successfully connected to remote server");
System.out.println("Connected to Server ... Code ::: "+ code);
}
result = client.login(uName,pwd);
}
catch(Exception e){
logger.error("Error ::: " + e.getMessage(),e);
e.printStackTrace();
}
return result;
}
// close connection
public void closeConnection(){
try {
client.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Disconnect Error ::: " + e.getMessage(),e);
e.printStackTrace();
}
}
// list all files
public List listAllFiles(){
try {
FTPFile[] ftpFile = client.listFiles();
List fileNames = new ArrayList();
System.out.println(fileNames.size());
for(FTPFile file : ftpFile){
fileNames.add(file.getName());
}
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("List Error ::: " + e.getMessage(),e);
e.printStackTrace();
}
return null;
}
// change the working directory
public boolean changeWorkingDirectory(String dirName){
boolean result = false;
try {
result = client.changeWorkingDirectory(dirName);
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Change Directory Error ::: " + e.getMessage(),e);
e.printStackTrace();
}
return result;
}
// delete the file
public String getCurrentWorkingDirectory(){
try {
return client.printWorkingDirectory();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
// put the file
public boolean putFile(String completePath){
boolean result = false;
try {
client.setFileType(FTP.ASCII_FILE_TYPE);
File f = new File(completePath);
if(f.exists()){
result = client.storeFile(f.getName(), new FileInputStream(f));
}
else
{
logger.info("File does not exist");
System.out.println("file does not exist");
}
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("File Transfer Error ::: " + e.getMessage(),e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("File Transfer Error ::: " + e.getMessage(),e);
}
return result;
}
// receive the file
public InputStream getFile(String fileName){
InputStream iStream=null;
try {
client.setFileType(FTP.ASCII_FILE_TYPE);
iStream = client.retrieveFileStream(fileName);
// iStream.close();
System.out.println("File Transfer Successfull");
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("File Transfer Error ::: " + e.getMessage(),e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("File Transfer Error ::: " + e.getMessage(),e);
}
return iStream;
}
public boolean deleteFile(String fileName){
boolean result=false;
try {
result = client.deleteFile(fileName);
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("File Transfer Error ::: " + e.getMessage(),e);
e.printStackTrace();
}
return result;
}
}

Wednesday, March 2, 2011

What is the difference between http and https

Don't know how many of you are aware of this difference, but it is worth sending to those that may not.

The main difference between http:/// <http:///> and https:// is it's all about keeping you secure. HTTP stands for Hyper Text Transfer Protocol.

The S (big surprise) stands for "Secure". If you visit a Website or webpage, and look at the address in the web browser, it will likely begin with the following: http://. <http://./> 

This means that the website is talking to your browser using the regular 'unsecure' language. In other words, it is possible for someone to "eavesdrop" on your computer's conversation with the Website. If you fill out a form on the website, someone might see the information you send to that site.


This is why you never ever enter your credit card number in an Http website ! But, if the web address begins with https://, <https://,/> that basically means your computer is talking to the website in a Secure code that no one can eavesdrop on.
If a website ever asks you to enter your credit card Information, you should automatically look to see if the web address begins with https://.

If it doesn't, you should NEVER enter sensitive information such as a credit card number.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Sweet Tomatoes Printable Coupons
Increase traffic