Secure FTP Factory

com.jscape.filetransfer
Class FtpTransfer

java.lang.Object
  extended by com.jscape.filetransfer.FtpTransfer
All Implemented Interfaces:
FileTransfer

public class FtpTransfer
extends java.lang.Object
implements FileTransfer

Implements the basic functionality of a FTP client.

Example Usage:

  // create new FtpTransfer instance
  FileTransfer ftp = new FtpTransfer("ftp.myserver.com","anonymous","user@myserver.com");
  try {
  // connect to FTP server
  ftp.connect();
  <p/>
  // print out directory listing
  System.out.println(ftp.getDirListingAsString());
  <p/>
  // disconnect from FTP server
  ftp.disconnect();
  } catch(Exception e) {
  System.out.println(e);
  }
 


Field Summary
 
Fields inherited from interface com.jscape.filetransfer.FileTransfer
ASCII, AUTO, BINARY, CURRENT_DIR, UP_DIR
 
Constructor Summary
FtpTransfer()
          Creates FtpTransfer instance.
FtpTransfer(java.lang.String host, java.lang.String user, java.lang.String pwd)
          Creates FtpTransfer instance.
FtpTransfer(java.lang.String host, java.lang.String user, java.lang.String pwd, java.io.File localDirectory)
          Creates FtpTransfer instance.
FtpTransfer(java.lang.String host, java.lang.String user, java.lang.String pwd, int port)
          Creates FtpTransfer instance.
FtpTransfer(java.lang.String host, java.lang.String user, java.lang.String pwd, java.lang.Integer port)
          Creates FtpTransfer instance.
 
Method Summary
 void abortDownloadThreads()
          Abort all download threads.
 void abortUploadThreads()
          Abort all upload threads.
 void addFileTransferListener(FileTransferListener listener)
          See FileTransfer interface for method description.
 void changePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Changes the password.
 void checksum(java.io.File localFile, java.lang.String remoteFile)
           
 void clearProxySettings()
          Clears proxy server values.
 void connect()
          Connects to server and performs login.
 void connect(boolean login)
          Establishes a connection with FTP server with optional login
 void deleteDir(java.lang.String name)
          See FileTransfer interface for method description.
 void deleteDir(java.lang.String name, boolean recursive)
          See FileTransfer interface for method description.
 void deleteFile(java.lang.String remoteFile)
          See FileTransfer interface for method description.
 void disconnect()
          See FileTransfer interface for method description.
 void download(java.io.OutputStream out, java.lang.String remoteFile)
          See FileTransfer interface for method description.
 java.io.File download(java.lang.String remoteFile)
          See FileTransfer interface for method description.
 java.io.File download(java.lang.String localFile, java.lang.String remoteFile)
          See FileTransfer interface for method description.
 void downloadDir(java.lang.String remoteDir)
          See FileTransfer interface for method description.
 void downloadDir(java.lang.String remoteDir, int retryLimit, boolean performChecksum)
          Downloads remote directory and contents.
 void downloadDir(java.lang.String remoteDir, int retryLimit, boolean performChecksum, int threadCount)
          Downloads remote directory and contents.
 int getBlockTransferSize()
          Gets blocksize for use in transferring files.
 boolean getDebug()
          See FileTransfer interface for method description.
 java.io.PrintStream getDebugStream()
          See FileTransfer interface for method description.
 java.lang.String getDir()
          See FileTransfer interface for method description.
 java.util.Enumeration getDirListing()
          See FileTransfer interface for method description.
 java.util.Enumeration getDirListing(java.lang.String filter)
          See FileTransfer interface for method description.
 java.lang.String getDirListingAsString()
          See FileTransfer interface for method description.
 java.lang.String getDirListingAsString(java.lang.String filter)
          See FileTransfer interface for method description.
 boolean getErrorOnSizeCommand()
          Gets the error on size command indicator.
 long getFilesize(java.lang.String remoteFile)
          See FileTransfer interface for method description.
 java.util.Date getFileTimestamp(java.lang.String remoteFile)
          See FileTransfer interface for method description.
 java.lang.String getHostname()
          See FileTransfer interface for method description.
 java.lang.Object getImplementation()
          See FileTransfer interface for method description.
 java.io.InputStream getInputStream(java.lang.String remoteFile, long pos)
          See FileTransfer interface for method description.
 java.lang.String getLocalChecksum(java.io.File localFile)
          Returns local checksum.
 java.io.File getLocalDir()
          See FileTransfer interface for method description.
 java.util.Enumeration getLocalDirListing()
          See FileTransfer interface for method description.
 int getMode()
          See FileTransfer interface for method description.
 java.util.Enumeration getNameListing()
          See FileTransfer interface for method description.
 java.util.Enumeration getNameListing(java.lang.String filter)
          See FileTransfer interface for method description.
 java.io.OutputStream getOutputStream(java.lang.String fileName, long off, boolean append)
          See FileTransfer interface for method description.
 boolean getPassive()
          See FileTransfer interface for method description.
 java.lang.String getPassword()
          See FileTransfer interface for method description.
 int getPort()
          See FileTransfer interface for method description.
 int getRecursiveDirectoryFileCount(java.lang.String directory)
           
 long getRecursiveDirectorySize(java.lang.String directory)
           
 java.lang.String getRemoteFileChecksum(java.lang.String remoteFile)
          Returns remote file checksum.
 java.util.Vector getRemoteFileList(java.lang.String directory)
           
 long getTimeout()
          See FileTransfer interface for method description.
 boolean getUseEPSV()
          Gets use EPSV value.
 java.lang.String getUsername()
          See FileTransfer interface for method description.
 java.lang.String getWireEncoding()
          Gets encoding set used when issuing commands and transferring files
 void interrupt()
          See FileTransfer interface for method description.
 boolean interrupted()
          See FileTransfer interface for method description.
 boolean isConnected()
          See FileTransfer interface for method description.
 boolean isFeatureSupported(java.lang.String command)
           
 void issueCommand(java.lang.String command)
          Issues command to the server.
 void login()
          Logs into FTP server after establishing a connection.
 void makeDir(java.lang.String name)
          See FileTransfer interface for method description.
 void makeDirRecursive(java.lang.String name)
          See FileTransfer interface for method description.
 java.io.File makeLocalDir(java.lang.String name)
          See FileTransfer interface for method description.
 void mdelete(java.lang.String filter)
          Deletes multiple files matching filter to FTP server's current directory.
 void mdownload(java.util.Enumeration fileNames)
          See FileTransfer interface for method description.
 void mdownload(java.lang.String filter)
          See FileTransfer interface for method description.
 void mupload(java.util.Enumeration fileNames)
          See FileTransfer interface for method description.
 void mupload(java.lang.String filter)
          See FileTransfer interface for method description.
 void removeFileTransferListener(FileTransferListener listener)
          See FileTransfer interface for method description.
 void renameFile(java.lang.String remoteFile, java.lang.String newFile)
          See FileTransfer interface for method description.
 void reset()
          See FileTransfer interface for method description.
 void resumeDownload(java.lang.String remoteFile, long offset)
          See FileTransfer interface for method description.
 void resumeDownload(java.lang.String localFile, java.lang.String remoteFile, long offset)
          See FileTransfer interface for method description.
 void resumeUpload(java.io.File file, long offset)
          See FileTransfer interface for method description.
 void resumeUpload(java.lang.String file, long offset)
          See FileTransfer interface for method description.
 void setAscii()
          See FileTransfer interface for method description.
 void setAuto(boolean auto)
          See FileTransfer interface for method description.
 void setAutoDetectIpv6(boolean autoDetect)
          Set auto detect Ipv6.
 void setBinary()
          See FileTransfer interface for method description.
 void setBlockTransferSize(int blocksize)
          Sets block size for use in transferring files.
 void setCompression(boolean compression)
          Sets whether the data will be compressed during the transfering.
 void setConnectBeforeCommand(boolean before)
          Sets the connectBefore property value
 void setDebug(boolean debug)
          See FileTransfer interface for method description.
 void setDebugStream(java.io.PrintStream ps)
          See FileTransfer interface for method description.
 void setDir(java.lang.String name)
          See FileTransfer interface for method description.
 void setDirUp()
          See FileTransfer interface for method description.
 void setErrorOnSizeCommand(boolean error)
          Sets the indicator value which will be used by methods that invokes getFileSize.
 void setFileTimestamp(java.lang.String remoteFile, java.util.Date dateFile)
          See FileTransfer interface for method description.
 void setHostname(java.lang.String host)
          See FileTransfer interface for method description.
 void setLocalDir(java.io.File dir)
          See FileTransfer interface for method description.
 void setNATAddress(java.lang.String ipAddress)
          Sets a NAT address which will be used after PASV command.
 void setPassive(boolean passive)
          See FileTransfer interface for method description.
 void setPassword(java.lang.String password)
          See FileTransfer interface for method description.
 void setPort(int port)
          See FileTransfer interface for method description.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the proxy authentication username and password to use with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this connection.
 void setTimeout(long timeout)
          See FileTransfer interface for method description.
 void setUseEPRT(boolean useEPRT)
          Sets use EPRT indicator.
 void setUseEPSV(boolean useEPSV)
          Sets use EPSV indicator.
 void setUseExtendedDirectoryListing(boolean useExtendedDirectoryListing)
          Sets the use extended directory listing field.
 void setUsername(java.lang.String username)
          See FileTransfer interface for method description.
 void setWireEncoding(java.lang.String encoding)
          Sets encoding set used when issuing commands and transferring files.
 void upload(byte[] data, java.lang.String name)
          See FileTransfer interface for method description.
 void upload(byte[] data, java.lang.String name, boolean append)
          See FileTransfer interface for method description.
 void upload(java.io.File file)
          See FileTransfer interface for method description.
 void upload(java.io.File file, boolean append)
          See FileTransfer interface for method description.
 void upload(java.io.File file, java.lang.String remoteName)
          See FileTransfer interface for method description.
 void upload(java.io.File file, java.lang.String remoteName, boolean append)
          See FileTransfer interface for method description.
 void upload(java.lang.String name)
          See FileTransfer interface for method description.
 void upload(java.lang.String name, boolean append)
          See FileTransfer interface for method description.
 void upload(java.lang.String extension, java.io.File file)
          Uploads a file to server with the extension specified by the argument.
 void upload(java.lang.String name, java.lang.String remoteName)
          See FileTransfer interface for method description.
 void upload(java.lang.String name, java.lang.String remoteName, boolean append)
          See FileTransfer interface for method description.
 void uploadDir(java.io.File localDir)
          See FileTransfer interface for method description.
 void uploadDir(java.io.File localDir, int retryLimit, boolean performChecksum, java.lang.String extension)
          Uploads local directory and contents.
 void uploadDir(java.io.File localDir, int retryLimit, boolean performChecksum, java.lang.String extension, int threadCount)
          Uploads local directory and contents.
 void uploadDir(java.io.File localDir, int retryLimit, int retryInterval, boolean performChecksum, java.lang.String extension)
          Uploads local directory and contents.
 void uploadDir(java.io.File localDir, java.lang.String extension)
          Uploads local directory and contents recursively to server.
 java.lang.String uploadUnique(java.io.File file)
          See FileTransfer interface for method description.
 java.lang.String uploadUnique(java.io.InputStream in, java.lang.String fileName)
          See FileTransfer interface for method description.
 java.lang.String uploadUnique(java.lang.String fileName)
          See FileTransfer interface for method description.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FtpTransfer

public FtpTransfer()
Creates FtpTransfer instance.


FtpTransfer

public FtpTransfer(java.lang.String host,
                   java.lang.String user,
                   java.lang.String pwd)
Creates FtpTransfer instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user

FtpTransfer

public FtpTransfer(java.lang.String host,
                   java.lang.String user,
                   java.lang.String pwd,
                   int port)
Creates FtpTransfer instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
port - the port of FTP server

FtpTransfer

public FtpTransfer(java.lang.String host,
                   java.lang.String user,
                   java.lang.String pwd,
                   java.lang.Integer port)
Creates FtpTransfer instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
port - the port of FTP server

FtpTransfer

public FtpTransfer(java.lang.String host,
                   java.lang.String user,
                   java.lang.String pwd,
                   java.io.File localDirectory)
Creates FtpTransfer instance.

Parameters:
host - the hostname of FTP server
user - the username of FTP user
pwd - the password of FTP user
localDirectory - the local directory to be used for uploading / downloading files
Method Detail

connect

public void connect()
             throws FileTransferException
Description copied from interface: FileTransfer
Connects to server and performs login.

Specified by:
connect in interface FileTransfer
Throws:
FileTransferException - FileTransferException instance
See Also:
FileTransfer.setUsername(java.lang.String), FileTransfer.setPassword(java.lang.String)

connect

public void connect(boolean login)
             throws FileTransferException
Establishes a connection with FTP server with optional login

Parameters:
login - true to login, false otherwise
Throws:
FileTransferException

login

public void login()
           throws FileTransferException
Logs into FTP server after establishing a connection. This method should only be used if login is not performed automatically during connect.

Throws:
FileTransferException - if an I/O or protocol error occurs

issueCommand

public void issueCommand(java.lang.String command)
                  throws FileTransferException
Issues command to the server.

Parameters:
command - a command
Throws:
FileTransferException - if an error occurs

changePassword

public void changePassword(java.lang.String oldPassword,
                           java.lang.String newPassword)
                    throws FileTransferException
Changes the password.

Parameters:
oldPassword - the old password.
newPassword - the new password.
Throws:
FileTransferException - if I/O or protocol error occurs.

deleteDir

public void deleteDir(java.lang.String name)
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
deleteDir in interface FileTransfer
Parameters:
name - the directory to remove
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.deleteDir(String)

deleteDir

public void deleteDir(java.lang.String name,
                      boolean recursive)
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
deleteDir in interface FileTransfer
Parameters:
name - the directory to remove
recursive - true if it should delete files and subdirectories within directory
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.deleteDir(String, boolean)

deleteFile

public void deleteFile(java.lang.String remoteFile)
                throws FileTransferException
See FileTransfer interface for method description.

Specified by:
deleteFile in interface FileTransfer
Parameters:
remoteFile - name of file to delete
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.deleteFile(String)

disconnect

public void disconnect()
                throws FileTransferException
See FileTransfer interface for method description.

Specified by:
disconnect in interface FileTransfer
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.disconnect()

download

public void download(java.io.OutputStream out,
                     java.lang.String remoteFile)
              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
download in interface FileTransfer
Parameters:
out - the OutputStream to write download to
remoteFile - remote filename
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.download(OutputStream, String)

download

public java.io.File download(java.lang.String remoteFile)
                      throws FileTransferException
See FileTransfer interface for method description.

Specified by:
download in interface FileTransfer
Parameters:
remoteFile - the file to download
Returns:
File the file downloaded
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.download(String)

download

public java.io.File download(java.lang.String localFile,
                             java.lang.String remoteFile)
                      throws FileTransferException
See FileTransfer interface for method description.

Specified by:
download in interface FileTransfer
Parameters:
localFile - destination filename
remoteFile - remote filename
Returns:
File the file downloaded
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.download(String, String)

downloadDir

public void downloadDir(java.lang.String remoteDir)
                 throws FileTransferException
See FileTransfer interface for method description.

Specified by:
downloadDir in interface FileTransfer
Parameters:
remoteDir - the directory to download
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.downloadDir(String)

downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        boolean performChecksum)
                 throws FileTransferException
Downloads remote directory and contents. Downloads are stored relative to current local directory.

Specified by:
downloadDir in interface FileTransfer
Parameters:
remoteDir - the directory to download
retryLimit - Retry number when an error occurs
performChecksum - Checksum perform indicator
Throws:
FtpException - if an I/O or protocol error occurs.
FileTransferException - if an I/O or protocol error occurs.

getDebug

public boolean getDebug()
See FileTransfer interface for method description.

Specified by:
getDebug in interface FileTransfer
Returns:
true if debugging is on
See Also:
FileTransfer.getDebug()

getDebugStream

public java.io.PrintStream getDebugStream()
See FileTransfer interface for method description.

Specified by:
getDebugStream in interface FileTransfer
Returns:
the PrintStream used in reporting debug statements
See Also:
FileTransfer.getDebugStream()

getDir

public java.lang.String getDir()
                        throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getDir in interface FileTransfer
Returns:
current directory
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getDir()

getDirListing

public java.util.Enumeration getDirListing()
                                    throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getDirListing in interface FileTransfer
Returns:
an Enumeration of FileTransferRemoteFile objects
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getDirListing()

getDirListing

public java.util.Enumeration getDirListing(java.lang.String filter)
                                    throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getDirListing in interface FileTransfer
Parameters:
filter - the filename filter
Returns:
an Enumeration of FileTransferRemoteFile objects
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getDirListing(String)

getDirListingAsString

public java.lang.String getDirListingAsString()
                                       throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getDirListingAsString in interface FileTransfer
Returns:
a directory listing
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getDirListingAsString()

getDirListingAsString

public java.lang.String getDirListingAsString(java.lang.String filter)
                                       throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getDirListingAsString in interface FileTransfer
Parameters:
filter - a filename filter
Returns:
a directory listing
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getDirListingAsString(String)

getFilesize

public long getFilesize(java.lang.String remoteFile)
                 throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getFilesize in interface FileTransfer
Parameters:
remoteFile - the remote file
Returns:
filesize in bytes
Throws:
FileTransferException - if an I/O or protocol error occurs.
See Also:
FileTransfer.getFilesize(String)

getFileTimestamp

public java.util.Date getFileTimestamp(java.lang.String remoteFile)
                                throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getFileTimestamp in interface FileTransfer
Parameters:
remoteFile - the remote file
Returns:
date the date/timestamp of remote file
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.getFileTimestamp(String)

setFileTimestamp

public void setFileTimestamp(java.lang.String remoteFile,
                             java.util.Date dateFile)
                      throws FileTransferException
See FileTransfer interface for method description.

Specified by:
setFileTimestamp in interface FileTransfer
Parameters:
remoteFile - the remote file
dateFile - the new date/timestamp
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.setFileTimestamp(String,Date)

getHostname

public java.lang.String getHostname()
See FileTransfer interface for method description.

Specified by:
getHostname in interface FileTransfer
Returns:
hostname
See Also:
FileTransfer.getHostname()

getLocalDir

public java.io.File getLocalDir()
See FileTransfer interface for method description.

Specified by:
getLocalDir in interface FileTransfer
Returns:
the local directory
See Also:
FileTransfer.getLocalDir()

getLocalDirListing

public java.util.Enumeration getLocalDirListing()
See FileTransfer interface for method description.

Specified by:
getLocalDirListing in interface FileTransfer
Returns:
an java.util.Enumeration of File
See Also:
FileTransfer.getLocalDirListing()

getMode

public int getMode()
See FileTransfer interface for method description.

Specified by:
getMode in interface FileTransfer
Returns:
the data transfer mode
See Also:
FileTransfer.getMode()

getNameListing

public java.util.Enumeration getNameListing()
                                     throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getNameListing in interface FileTransfer
Returns:
an Enumeration of String where each item represents a file or directory name
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.getNameListing()

getNameListing

public java.util.Enumeration getNameListing(java.lang.String filter)
                                     throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getNameListing in interface FileTransfer
Parameters:
filter - the filename filter
Returns:
an Enumeration of String where each item represents a file or directory name
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.getNameListing(String)

getPassive

public boolean getPassive()
See FileTransfer interface for method description.

Specified by:
getPassive in interface FileTransfer
Returns:
true if passive mode is used, false otherwise
See Also:
FileTransfer.getPassive()

getPassword

public java.lang.String getPassword()
See FileTransfer interface for method description.

Specified by:
getPassword in interface FileTransfer
Returns:
the password
See Also:
FileTransfer.getPassword()

getPort

public int getPort()
See FileTransfer interface for method description.

Specified by:
getPort in interface FileTransfer
Returns:
server port
See Also:
FileTransfer.getPort()

getTimeout

public long getTimeout()
See FileTransfer interface for method description.

Specified by:
getTimeout in interface FileTransfer
Returns:
timeout in milliseconds
See Also:
FileTransfer.getTimeout()

getUsername

public java.lang.String getUsername()
See FileTransfer interface for method description.

Specified by:
getUsername in interface FileTransfer
Returns:
username
See Also:
FileTransfer.getUsername()

interrupt

public void interrupt()
See FileTransfer interface for method description.

Specified by:
interrupt in interface FileTransfer
See Also:
FileTransfer.interrupt()

interrupted

public boolean interrupted()
See FileTransfer interface for method description.

Specified by:
interrupted in interface FileTransfer
Returns:
true if transfer process was interrupted.
See Also:
FileTransfer.interrupted()

isConnected

public boolean isConnected()
See FileTransfer interface for method description.

Specified by:
isConnected in interface FileTransfer
Returns:
true if connected false otherwise
See Also:
FileTransfer.isConnected()

makeDir

public void makeDir(java.lang.String name)
             throws FileTransferException
See FileTransfer interface for method description.

Specified by:
makeDir in interface FileTransfer
Parameters:
name - name of directory to make
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.makeDir(String)

makeDirRecursive

public void makeDirRecursive(java.lang.String name)
                      throws FileTransferException
See FileTransfer interface for method description.

Specified by:
makeDirRecursive in interface FileTransfer
Parameters:
name - full path of directory to make
Throws:
FileTransferException - if an I/O or server error occurs
See Also:
FileTransfer.makeDirRecursive(String)

mdelete

public void mdelete(java.lang.String filter)
             throws FileTransferException
Deletes multiple files matching filter to FTP server's current directory. Wildcards may be used to specify multiple files e.g. .*\.txt

Specified by:
mdelete in interface FileTransfer
Parameters:
filter - the regular expression filter to use
Throws:
FileTransferException - if an I/O or protocol error occurs.

makeLocalDir

public java.io.File makeLocalDir(java.lang.String name)
See FileTransfer interface for method description.

Specified by:
makeLocalDir in interface FileTransfer
Parameters:
name - name of directory
Returns:
the directory
See Also:
FileTransfer.makeLocalDir(String)

mdownload

public void mdownload(java.util.Enumeration fileNames)
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
mdownload in interface FileTransfer
Parameters:
fileNames - filenames of files to download
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.mdownload(Enumeration)

mdownload

public void mdownload(java.lang.String filter)
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
mdownload in interface FileTransfer
Parameters:
filter - the regular expression to use
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.mdownload(String)

mupload

public void mupload(java.util.Enumeration fileNames)
             throws FileTransferException
See FileTransfer interface for method description.

Specified by:
mupload in interface FileTransfer
Parameters:
fileNames - filenames of files to upload
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.mupload(Enumeration)

mupload

public void mupload(java.lang.String filter)
             throws FileTransferException
See FileTransfer interface for method description.

Specified by:
mupload in interface FileTransfer
Parameters:
filter - the regular expression to use
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.mupload(String)

renameFile

public void renameFile(java.lang.String remoteFile,
                       java.lang.String newFile)
                throws FileTransferException
See FileTransfer interface for method description.

Specified by:
renameFile in interface FileTransfer
Parameters:
remoteFile - name of file to rename
newFile - new name of file
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.renameFile(String, String)

reset

public void reset()
See FileTransfer interface for method description.

Specified by:
reset in interface FileTransfer
See Also:
FileTransfer.reset()

resumeDownload

public void resumeDownload(java.lang.String remoteFile,
                           long offset)
                    throws FileTransferException
See FileTransfer interface for method description.

Specified by:
resumeDownload in interface FileTransfer
Parameters:
remoteFile - the file to download
offset - file offset in bytes
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.resumeDownload(String, long)

resumeDownload

public void resumeDownload(java.lang.String localFile,
                           java.lang.String remoteFile,
                           long offset)
                    throws FileTransferException
See FileTransfer interface for method description.

Specified by:
resumeDownload in interface FileTransfer
Parameters:
localFile - local file name
remoteFile - the file to download
offset - file offset in bytes
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.resumeDownload(String, String, long)

resumeUpload

public void resumeUpload(java.io.File file,
                         long offset)
                  throws FileTransferException
See FileTransfer interface for method description.

Specified by:
resumeUpload in interface FileTransfer
Parameters:
file - the local file to upload
offset - file offset in bytes
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.resumeUpload(File, long)

resumeUpload

public void resumeUpload(java.lang.String file,
                         long offset)
                  throws FileTransferException
See FileTransfer interface for method description.

Specified by:
resumeUpload in interface FileTransfer
Parameters:
file - the local file to upload
offset - file offset in bytes
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.resumeUpload(String, long)

setAscii

public void setAscii()
              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
setAscii in interface FileTransfer
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.setAscii()

setAuto

public void setAuto(boolean auto)
See FileTransfer interface for method description.

Specified by:
setAuto in interface FileTransfer
Parameters:
auto - true to turn automatic detect on false to turn off
See Also:
FileTransfer.setAuto(boolean)

setBinary

public void setBinary()
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
setBinary in interface FileTransfer
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.setBinary()

setDebug

public void setDebug(boolean debug)
See FileTransfer interface for method description.

Specified by:
setDebug in interface FileTransfer
Parameters:
debug - true to turn debugging on
See Also:
FileTransfer.setDebug(boolean)

setDebugStream

public void setDebugStream(java.io.PrintStream ps)
See FileTransfer interface for method description.

Specified by:
setDebugStream in interface FileTransfer
Parameters:
ps - the PrintStream to send debug statements to
See Also:
FileTransfer.setDebugStream(PrintStream)

setDir

public void setDir(java.lang.String name)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
setDir in interface FileTransfer
Parameters:
name - the remote directory
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.setDir(String)

setDirUp

public void setDirUp()
              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
setDirUp in interface FileTransfer
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.setDirUp()

setHostname

public void setHostname(java.lang.String host)
See FileTransfer interface for method description.

Specified by:
setHostname in interface FileTransfer
Parameters:
host - the hostname or IP address of server
See Also:
FileTransfer.setHostname(String)

setLocalDir

public void setLocalDir(java.io.File dir)
See FileTransfer interface for method description.

Specified by:
setLocalDir in interface FileTransfer
Parameters:
dir - the local directory
See Also:
FileTransfer.setLocalDir(File)

setErrorOnSizeCommand

public void setErrorOnSizeCommand(boolean error)
Sets the indicator value which will be used by methods that invokes getFileSize.

Parameters:
error - Error indicator value

getErrorOnSizeCommand

public boolean getErrorOnSizeCommand()
Gets the error on size command indicator.

Returns:
true then method which invokes getFileSize will throw an exception when it caused an error, false the error will be ignored.

setNATAddress

public void setNATAddress(java.lang.String ipAddress)
                   throws FileTransferException
Sets a NAT address which will be used after PASV command.

Parameters:
ipAddress - The NAT IP address.
Throws:
FtpException - If an error occurs.
FileTransferException

setPassive

public void setPassive(boolean passive)
See FileTransfer interface for method description.

Specified by:
setPassive in interface FileTransfer
Parameters:
passive - if true, the transfers will be passive.
See Also:
FileTransfer.setPassive(boolean)

setPassword

public void setPassword(java.lang.String password)
See FileTransfer interface for method description.

Specified by:
setPassword in interface FileTransfer
Parameters:
password - the password
See Also:
FileTransfer.setPassword(String)

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the proxy authentication username and password to use with proxy server. To clear these settings invoke the #clearProxySettings method.

Specified by:
setProxyAuthentication in interface FileTransfer
Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this connection. To clear these settings invoke the #clearProxySettings method.

Specified by:
setProxyHost in interface FileTransfer
Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server to connect to
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.

Specified by:
setProxyType in interface FileTransfer
Parameters:
proxyType - The proxy type. Values allowed: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.

Specified by:
clearProxySettings in interface FileTransfer

setTimeout

public void setTimeout(long timeout)
See FileTransfer interface for method description.

Specified by:
setTimeout in interface FileTransfer
Parameters:
timeout - the timeout in milliseconds
See Also:
FileTransfer.setTimeout(long)

setUsername

public void setUsername(java.lang.String username)
See FileTransfer interface for method description.

Specified by:
setUsername in interface FileTransfer
Parameters:
username - the username
See Also:
FileTransfer.setUsername(String)

setUseEPSV

public void setUseEPSV(boolean useEPSV)
Sets use EPSV indicator. When it is true then will be sent EPSV.

Parameters:
useEPSV - The use EPSV value

setAutoDetectIpv6

public void setAutoDetectIpv6(boolean autoDetect)
Set auto detect Ipv6.

Parameters:
useIpv6 -

setUseEPRT

public void setUseEPRT(boolean useEPRT)
Sets use EPRT indicator.

Parameters:
useEPRT -

setUseExtendedDirectoryListing

public void setUseExtendedDirectoryListing(boolean useExtendedDirectoryListing)
Sets the use extended directory listing field.

Parameters:
useExtendedDirectoryListing - The use extended directory listing indicator.

getUseEPSV

public boolean getUseEPSV()
Gets use EPSV value.

Returns:
true the pasive mode will be sent EPSV command

setWireEncoding

public void setWireEncoding(java.lang.String encoding)
Sets encoding set used when issuing commands and transferring files. The default encoding is UTF8

Specified by:
setWireEncoding in interface FileTransfer
Parameters:
encoding - the character encoding to be used

setConnectBeforeCommand

public void setConnectBeforeCommand(boolean before)
Sets the connectBefore property value

Parameters:
before - It indicates if the connection will be established before send the command in passive mode

getWireEncoding

public java.lang.String getWireEncoding()
Gets encoding set used when issuing commands and transferring files

Specified by:
getWireEncoding in interface FileTransfer
Returns:
Returns the encoding is being used

getRemoteFileChecksum

public java.lang.String getRemoteFileChecksum(java.lang.String remoteFile)
                                       throws FtpException
Returns remote file checksum.

Parameters:
remoteFile - remote file
Returns:
remote file checksum.
Throws:
FtpException - if an error occurs

getLocalChecksum

public java.lang.String getLocalChecksum(java.io.File localFile)
                                  throws FtpException
Returns local checksum.

Parameters:
localFile - File which will be calculate the checksum
Returns:
checksum Compute value
Throws:
FtpException - if an error occurs

upload

public void upload(byte[] data,
                   java.lang.String name)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
data - the raw contents of the file to upload
name - the filename to store file as on FTP server
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(byte[], String)

upload

public void upload(byte[] data,
                   java.lang.String name,
                   boolean append)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
data - the raw contents of the file to upload
name - the filename to store file as on server
append - true to append to remote file on FTP server, false otherwise
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(byte[], String, boolean)

upload

public void upload(java.io.File file)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
file - the local file to upload
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(File)

upload

public void upload(java.io.File file,
                   boolean append)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
file - the local file to upload
append - true to append to remote file on server, false otherwise
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(File, boolean)

upload

public void upload(java.lang.String extension,
                   java.io.File file)
            throws FileTransferException
Uploads a file to server with the extension specified by the argument. After the file has been uploaded then the file name is renamed to the original file name.

Specified by:
upload in interface FileTransfer
Parameters:
extension - The extension file will be used to upload the file.
file - The file will be uploaded
Throws:
FileTransferException

upload

public void upload(java.io.File file,
                   java.lang.String remoteName)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
file - the local file to upload
remoteName - the destination filename of upload
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(File, String)

upload

public void upload(java.io.File file,
                   java.lang.String remoteName,
                   boolean append)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
file - the local file to upload
remoteName - the destination filename of upload
append - true to append to remote file on server, false otherwise
Throws:
FileTransferException - if an I/O or server related error occurs
See Also:
FileTransfer.upload(File, String, boolean)

upload

public void upload(java.lang.String name)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
name - the local file to upload
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.upload(String)

upload

public void upload(java.lang.String name,
                   boolean append)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
name - the local file to upload
append - true to append to remote file on server, false otherwise
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.upload(String, boolean)

upload

public void upload(java.lang.String name,
                   java.lang.String remoteName)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
name - the local file to upload
remoteName - the destination of upload
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.upload(String, String)

upload

public void upload(java.lang.String name,
                   java.lang.String remoteName,
                   boolean append)
            throws FileTransferException
See FileTransfer interface for method description.

Specified by:
upload in interface FileTransfer
Parameters:
name - the local file to upload
remoteName - the destination of upload
append - true to append to remote file on FTP server, false otherwise
Throws:
FileTransferException - if an I/O or server error occurs.
See Also:
FileTransfer.upload(String, String, boolean)

uploadUnique

public java.lang.String uploadUnique(java.lang.String fileName)
                              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
uploadUnique in interface FileTransfer
Parameters:
fileName - the file to be uploaded relative to current local directory
Returns:
the resulting unique filename on server
Throws:
FileTransferException - if an I/O or protocol error occurs.
See Also:
FileTransfer.uploadUnique(String)

uploadUnique

public java.lang.String uploadUnique(java.io.File file)
                              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
uploadUnique in interface FileTransfer
Parameters:
file - the file to be uploaded
Returns:
the resulting unique filename on server
Throws:
FileTransferException - if an I/O or protocol error occurs.
See Also:
FileTransfer.uploadUnique(File)

uploadUnique

public java.lang.String uploadUnique(java.io.InputStream in,
                                     java.lang.String fileName)
                              throws FileTransferException
See FileTransfer interface for method description.

Specified by:
uploadUnique in interface FileTransfer
Parameters:
in - the InputStream to upload file from
fileName - the filename to be used as seed value for determining unique filename
Returns:
the resulting unique filename on server
Throws:
FileTransferException - if an I/O or protocol error occurs.
See Also:
FileTransfer.uploadUnique(InputStream,String)

uploadDir

public void uploadDir(java.io.File localDir)
               throws FileTransferException
See FileTransfer interface for method description.

Specified by:
uploadDir in interface FileTransfer
Parameters:
localDir - the directory to upload
Throws:
FileTransferException - if an I/O or protocol error occurs.
See Also:
FileTransfer.uploadDir(File)

uploadDir

public void uploadDir(java.io.File localDir,
                      java.lang.String extension)
               throws FileTransferException
Uploads local directory and contents recursively to server. Uploads are stored relative to current remote directory. Files are uploaded with the extension specified in the argument extension but when the upload has finished the remote file name is renamed to the original file name.

Specified by:
uploadDir in interface FileTransfer
Parameters:
localDir - the directory to upload
extension - The extension file name used to upload each file
Throws:
FileTransferException - if an I/O or protocol error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      boolean performChecksum,
                      java.lang.String extension)
               throws FileTransferException
Uploads local directory and contents. Uploads are stored relative to current remote directory.

Specified by:
uploadDir in interface FileTransfer
Parameters:
localDir - the directory to upload
retryLimit - Retry number when an error occurs
performChecksum - Checksum perform indicator
extension - The extension which will be used to upload the files
Throws:
FtpException - if an I/O or protocol error occurs.
FileTransferException - if an I/O or protocol related error occurs.

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      int retryInterval,
                      boolean performChecksum,
                      java.lang.String extension)
               throws FileTransferException
Uploads local directory and contents. Uploads are stored relative to current remote directory.

Parameters:
localDir - the directory to upload
retryLimit - Retry number when an error occurs
retryInterval - the retry interval in seconds
performChecksum - Checksum perform indicator
extension - The extension which will be used to upload the files
Throws:
FtpException - if an I/O or protocol error occurs.
FileTransferException

addFileTransferListener

public void addFileTransferListener(FileTransferListener listener)
See FileTransfer interface for method description.

Specified by:
addFileTransferListener in interface FileTransfer
Parameters:
listener - the listener to add
See Also:
FileTransfer.addFileTransferListener(FileTransferListener)

removeFileTransferListener

public void removeFileTransferListener(FileTransferListener listener)
See FileTransfer interface for method description.

Specified by:
removeFileTransferListener in interface FileTransfer
Parameters:
listener - the listener to remove
See Also:
FileTransfer.removeFileTransferListener(FileTransferListener)

getInputStream

public java.io.InputStream getInputStream(java.lang.String remoteFile,
                                          long pos)
                                   throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getInputStream in interface FileTransfer
Parameters:
remoteFile - the remote file to get InputStream for
pos - the byte offset, 0 to get full file
Returns:
an InputStream
Throws:
FileTransferException - if an I/O or protocol related error occurs

getImplementation

public java.lang.Object getImplementation()
See FileTransfer interface for method description.

Specified by:
getImplementation in interface FileTransfer
Returns:
underlying file transfer implementation
See Also:
Ftp, Ftps

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String fileName,
                                            long off,
                                            boolean append)
                                     throws FileTransferException
See FileTransfer interface for method description.

Specified by:
getOutputStream in interface FileTransfer
Parameters:
fileName - the remote filename
off - the byte offset, 0 to write at beginning of file
append - true to append to remote file, false otherwise
Returns:
an OutputStream
Throws:
FileTransferException - if an I/O or protocol related error occurs

setBlockTransferSize

public void setBlockTransferSize(int blocksize)
Sets block size for use in transferring files.

Specified by:
setBlockTransferSize in interface FileTransfer
Parameters:
blocksize - the blocksize in bytes

getBlockTransferSize

public int getBlockTransferSize()
Gets blocksize for use in transferring files.

Specified by:
getBlockTransferSize in interface FileTransfer
Returns:
blocksize in bytes

setCompression

public void setCompression(boolean compression)
Sets whether the data will be compressed during the transfering.

Parameters:
compression - When it is true the data will be compressed before it is sent between the client and the server.

setPort

public void setPort(int port)
See FileTransfer interface for method description.

Specified by:
setPort in interface FileTransfer
Parameters:
port - the port
See Also:
FileTransfer.setPort(int)

isFeatureSupported

public boolean isFeatureSupported(java.lang.String command)
                           throws FileTransferException
Throws:
FileTransferException

checksum

public void checksum(java.io.File localFile,
                     java.lang.String remoteFile)
              throws FileTransferException
Throws:
FileTransferException

abortDownloadThreads

public void abortDownloadThreads()
Description copied from interface: FileTransfer
Abort all download threads. Used by the implementing classes Sftp, Ftp, Ftps to abort all spawned threads.

Specified by:
abortDownloadThreads in interface FileTransfer

abortUploadThreads

public void abortUploadThreads()
Description copied from interface: FileTransfer
Abort all upload threads. Used by the implementing classes Sftp, Ftp, Ftps to abort all spawned threads.

Specified by:
abortUploadThreads in interface FileTransfer

downloadDir

public void downloadDir(java.lang.String remoteDir,
                        int retryLimit,
                        boolean performChecksum,
                        int threadCount)
                 throws FileTransferException
Description copied from interface: FileTransfer
Downloads remote directory and contents. Downloads are stored relative to current local directory.

Specified by:
downloadDir in interface FileTransfer
Parameters:
remoteDir - the directory to download
retryLimit - retry limit if download fails
performChecksum - whether or not to perform checksum after download, only supported in FTP/S protocols and not by all FTP servers
threadCount - the thread count
Throws:
FileTransferException - if an I/O or protocol error occurs.

getRemoteFileList

public java.util.Vector getRemoteFileList(java.lang.String directory)
                                   throws FileTransferException
Specified by:
getRemoteFileList in interface FileTransfer
Throws:
FileTransferException

getRecursiveDirectoryFileCount

public int getRecursiveDirectoryFileCount(java.lang.String directory)
Specified by:
getRecursiveDirectoryFileCount in interface FileTransfer

getRecursiveDirectorySize

public long getRecursiveDirectorySize(java.lang.String directory)
Specified by:
getRecursiveDirectorySize in interface FileTransfer

uploadDir

public void uploadDir(java.io.File localDir,
                      int retryLimit,
                      boolean performChecksum,
                      java.lang.String extension,
                      int threadCount)
               throws FileTransferException
Description copied from interface: FileTransfer
Uploads local directory and contents. Uploads are stored relative to current remote directory.

Specified by:
uploadDir in interface FileTransfer
Parameters:
localDir - the directory to upload
retryLimit - retry number when an error occurs
performChecksum - whether or not to perform checksum verification
extension - the temporary extension which will be used when uploading files or null to use current extension
Throws:
FileTransferException - if an I/O or protocol related error occurs.

Secure FTP Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved