Scan document for virus – JAVA

07 Mar

Hi folks,

Here is the working code for to scan uploaded document and verify any virus effected or not.

Just follow the below steps to get execute and see the result.

1. create Interface VirusScanDemo

import org.apache.struts.upload.FormFile;

public interface VirusScanDemo {
public boolean scanForVirus(FormFile document);


2.create a class with method that implements above interface method.

public boolean scanForVirus(FormFile document){
boolean isSafe = true;
InputStream isStream = null;
try {
// After connection attempt, check the reply code to verify the success.
int reply = ftp.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();“FTP server refused connection.”);
return false;
ftp.login( userName, passwd );
// transfer file
if( destinationFolderName != null && destinationFolderName.trim().length() > 0 ){
// change the working directory
ftp.changeWorkingDirectory( destinationFolderName.trim() );
isStream = document.getInputStream();
boolean ftpStatus = ftp.storeFile(document.getFileName(), isStream);
String replyString = ftp.getReplyString();
if((!ftpStatus)||((replyString.indexOf(“226”)) < 0)){“Virus scan result -> ” + replyString + “File Name : ” + document.getFileName());
isSafe = false;
} catch(IOException e) {
isSafe = false;“IOException in FortigateFTPUtil scanForVirus() “+e);
} finally {
if(ftp.isConnected()) {
try {
} catch(IOException ioe) {
// do nothing
return isSafe;

For more details :

Here is the detailed explanation with example code

Happy Coding!.

Stay tuned to know more updates.

Have a nice day 🙂

Leave a comment

Posted by on March 7, 2013 in Uncategorized


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: