⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpservice.java

📁 一个实用工具类
💻 JAVA
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.net.ftp.service;import org.butor.log.Log;import org.butor.net.ftp.FtpClient;import org.butor.net.ftp.IFTPInputStreamConsumer;import java.net.Socket;/** * FTP service! * * @author Aiman Sawan */public abstract class FtpService {  	/**	 * Reference to the actual implementation of the service.	 */	protected static IFtpService s_ftpService;			public static final char ASCII_TRANSFER_MODE = FtpClient.ASCII_TRANSFER_MODE;	public static final char EBCDIC_TRANSFER_MODE = FtpClient.EBCDIC_TRANSFER_MODE;	public static final char BINARY_TRANSFER_MODE = FtpClient.BINARY_TRANSFER_MODE;/** * Change Directory *  * @param sessionName, name of the ftp session to use * @param dir String, name of remote directory. */public static boolean changeDirectory(String sessionName, String dir) {	if (s_ftpService != null) {		return s_ftpService.changeDirectory(sessionName, dir);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.changeDirectory()", "not yet initialized!");			}	return false;}/** * !AS *  * @param ... */public static boolean createDirectory(String sessionName, String dir) {	if (s_ftpService != null) {		return s_ftpService.createDirectory(sessionName, dir);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.createDirectory()", "not yet initialized!");			}	return false;}/** * Change Directory *  * @param sessionName, name of the ftp session to use * @param dir String, name of remote directory. */public static String currentDirectory(String sessionName) {	if (s_ftpService != null) {		return s_ftpService.currentDirectory(sessionName);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.currentDirectory()", "not yet initialized!");			}		return null;}/** * !AS *  * @param ... */public static boolean existsDirectory(String sessionName, String dir) {	if (s_ftpService != null) {		return s_ftpService.existsDirectory(sessionName, dir);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.existsDirectory()", "not yet initialized!");			}	return false;}/** * Checks if a particular file exists in current directory. *  * @param sessionName * @param file * @return */public static boolean fileExists(String sessionName, String file) {	if (s_ftpService != null) {		return s_ftpService.fileExists(sessionName, file);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.fileExists()", "not yet initialized!");			}	return false;	}/** * Gets Socket of stored file.  * The file will be created on remote and a socket on it will be returned to * makes writes on its output stream. * * @param sessionName, name of the ftp session to use * @param remoteFile String, name of remote file to create. */public static Socket getSocketToStoreFile(String sessionName, String remoteFile) {	if (s_ftpService != null) {		return s_ftpService.getSocketToStoreFile(sessionName, remoteFile);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.getSocketToSotreFile()", "not yet initialized!");			}	return null;}/** * Binds an instance of an implementor of IIrisFileImager * * @param service Object that will give the server Iris File Imager. */public static void register(IFtpService service) {	s_ftpService = service;	Log.logStr(null, Log.LOG_TYPE_INFO,		"FtpService.register()", "");		}/** * !AS *  * @param ... */public static boolean retrieveFile(String sessionName, String localFile, String remoteFile, char type) {	if (s_ftpService != null) {		return s_ftpService.retrieveFile(sessionName, localFile, remoteFile, type);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.retrieveFile()", "not yet initialized!");			}	return false;}/** * !AS *  * @param ... */public static StringBuffer retrieveFileSB(String sessionName, String remoteFile) {	return retrieveFileSB(sessionName, remoteFile, FtpService.BINARY_TRANSFER_MODE);}public static StringBuffer retrieveFileSB(String sessionName, String remoteFile, char transferType) {	if (s_ftpService != null) {		return s_ftpService.retrieveFileSB(sessionName, remoteFile, transferType);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.retrieveFileSB()", "not yet initialized!");			}	return null;}/** * Philip Whitford * @param sessionName, name of the ftp session to use * @param file, the file name * @param reader, the implementation that will read the requested file * @param transferType, Ex ASCII_TRANSFER_MODE, BINARY_TRANSFER_MODE...etc */  public static void retrieveFileToConsumer(String sessionName, String path, String file, char transferType, IFTPInputStreamConsumer inStreamConsumer) {	if (s_ftpService != null) {		s_ftpService.retrieveFileToConsumer(sessionName, path, file,  transferType, inStreamConsumer);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"retrieveFileToConsumer()" + sessionName, "not yet initialized!");			}}/** * @return a directory content list * * @param sessionName, name of the ftp session to use * @param dir, directory to list */public static String[] retrieveList(String sessionName, String dir, boolean detail) {	if (s_ftpService != null) {		return s_ftpService.retrieveList(sessionName, dir, detail);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.retrieveList()", "not yet initialized!");			}	return null;}/** * !AS *  * @param ... */public static boolean storeFile(String sessionName, String localFile, String remoteFile, char type) {	if (s_ftpService != null) {		return s_ftpService.storeFile(sessionName, localFile, remoteFile, type);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.storeFile()", "not yet initialized!");			}	return false;}/** * @param ... */public static boolean storeFileSB(String sessionName, StringBuffer buf, String remoteFile, char type) {	if (s_ftpService != null) {		return s_ftpService.storeFileSB(sessionName, buf, remoteFile, type);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.storeFile()", "not yet initialized!");			}	return false;}/** * !AS *  * @param ... */public static StringBuffer unzipFileSB(String sessionName, String remoteFile) {	if (s_ftpService != null) {		return s_ftpService.unzipFileSB(sessionName, remoteFile);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.zipFile()", "not yet initialized!");			}	return null;}/** * !AS *  * @param ... */public static boolean zipFileSB(String sessionName, StringBuffer buf, String remoteFile) {	if (s_ftpService != null) {		return s_ftpService.zipFileSB(sessionName, buf, remoteFile);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.zipFile()", "not yet initialized!");			}	return false;}/************ * pw *  *************/public static boolean changeFilePermission(String sessionName, String newPermission, String fileName) {	if (s_ftpService != null) {		return s_ftpService.changeFilePermission(sessionName, newPermission, fileName);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.changePermission()", "not yet initialized!");			}	return false;}public static boolean deleteFile(String sessionName, String remoteFile) {	if (s_ftpService != null) {		return s_ftpService.deleteFile(sessionName, remoteFile);	} else {		Log.logStr(null, Log.LOG_TYPE_WARN,			"FtpService.deleteFile()", "not yet initialized!");			}	return false;}		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -