Package org.javlo.macro.interactive
Class TransfertStaticToFtp
- java.lang.Object
-
- java.lang.Thread
-
- org.javlo.macro.interactive.TransfertStaticToFtp
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description boolean
running
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description TransfertStaticToFtp(ContentContext ctx, File folder, URL url, String host, int port, String username, String password, String path, MailService mailService, String email)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
createDirectories(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirPath, File localDir, String remoteParentDir)
File
getFolder()
String
getHost()
String
getPassword()
String
getPath()
int
getPort()
URL
getUrl()
String
getUsername()
static void
main(String[] args)
static boolean
makeDirectories(org.apache.commons.net.ftp.FTPClient ftpClient, String dirPath)
Creates a nested directory structure on a FTP serverstatic void
removeDirectory(org.apache.commons.net.ftp.FTPClient ftpClient, String parentDir, String currentDir)
Removes a non-empty directory by delete all its sub files and sub directories recursively.void
run()
void
setFolder(File folder)
void
setHost(String host)
void
setPassword(String password)
void
setPath(String path)
void
setPort(int port)
void
setUrl(URL url)
void
setUsername(String username)
int
uploadDirectory(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirPath, File localDir, String remoteParentDir)
Upload a whole directory (including its nested sub directories and files) to a FTP server.static boolean
uploadSingleFile(org.apache.commons.net.ftp.FTPClient ftpClient, String localFilePath, String remoteFilePath)
Upload a single file to the FTP server.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
TransfertStaticToFtp
public TransfertStaticToFtp(ContentContext ctx, File folder, URL url, String host, int port, String username, String password, String path, MailService mailService, String email)
-
-
Method Detail
-
getHost
public String getHost()
-
setHost
public void setHost(String host)
-
getPort
public int getPort()
-
setPort
public void setPort(int port)
-
getUsername
public String getUsername()
-
setUsername
public void setUsername(String username)
-
getPassword
public String getPassword()
-
setPassword
public void setPassword(String password)
-
getFolder
public File getFolder()
-
setFolder
public void setFolder(File folder)
-
getUrl
public URL getUrl()
-
setUrl
public void setUrl(URL url)
-
getPath
public String getPath()
-
setPath
public void setPath(String path)
-
uploadSingleFile
public static boolean uploadSingleFile(org.apache.commons.net.ftp.FTPClient ftpClient, String localFilePath, String remoteFilePath) throws IOException
Upload a single file to the FTP server.- Parameters:
ftpClient
- an instance of org.apache.commons.net.ftp.FTPClient class.localFilePath
- Path of the file on local computerremoteFilePath
- Path of the file on remote the server- Returns:
- true if the file was uploaded successfully, false otherwise
- Throws:
IOException
- if any network or IO error occurred.
-
makeDirectories
public static boolean makeDirectories(org.apache.commons.net.ftp.FTPClient ftpClient, String dirPath) throws IOException
Creates a nested directory structure on a FTP server- Parameters:
ftpClient
- an instance of org.apache.commons.net.ftp.FTPClient class.dirPath
- Path of the directory, i.e /projects/java/ftp/demo- Returns:
- true if the directory was created successfully, false otherwise
- Throws:
IOException
- if any error occurred during client-server communication
-
createDirectories
public int createDirectories(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirPath, File localDir, String remoteParentDir) throws IOException
- Throws:
IOException
-
uploadDirectory
public int uploadDirectory(org.apache.commons.net.ftp.FTPClient ftpClient, String remoteDirPath, File localDir, String remoteParentDir) throws IOException
Upload a whole directory (including its nested sub directories and files) to a FTP server.- Parameters:
ftpClient
- an instance of org.apache.commons.net.ftp.FTPClient class.remoteDirPath
- Path of the destination directory on the server.localParentDir
- Path of the local directory being uploaded.remoteParentDir
- Path of the parent directory of the current directory on the server (used by recursive calls).- Throws:
IOException
- if any network or IO error occurred.
-
removeDirectory
public static void removeDirectory(org.apache.commons.net.ftp.FTPClient ftpClient, String parentDir, String currentDir) throws IOException
Removes a non-empty directory by delete all its sub files and sub directories recursively. And finally remove the directory.- Throws:
IOException
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
-