天天看點

java ftp storefile_Java FTPClient.storeFile方法代碼示例

本文整理匯總了Java中org.apache.commons.net.ftp.FTPClient.storeFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FTPClient.storeFile方法的具體用法?Java FTPClient.storeFile怎麽用?Java FTPClient.storeFile使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.net.ftp.FTPClient的用法示例。

在下文中一共展示了FTPClient.storeFile方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: uploadFile

​點讚 5

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public boolean uploadFile(File file) {

boolean result = false;

FTPClient ftpClient = ftpConnManager.getFTPClient();

if (null == ftpClient || !ftpClient.isConnected()) {

return result;

}

try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file.getPath()))) {

boolean storeFile = ftpClient.storeFile(file.getName(), in);

if (storeFile) {

result = true;

log.info("file-->" + file.getPath() + "成功上傳至FTP服務器");

}

} catch (Exception e) {

log.error("error", e);

} finally {

disconnect(ftpClient);

}

return result;

}

開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:25,

示例2: uploadFile

​點讚 3

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

protected void uploadFile(final FTPClient ftpClient, final String sourceFilePath, final String targetFilePath,

final String logPrefix) throws IOException {

log.info(String.format(UPLOAD_FILE, logPrefix, sourceFilePath, targetFilePath));

final File sourceFile = new File(sourceFilePath);

try (final InputStream is = new FileInputStream(sourceFile)) {

ftpClient.changeWorkingDirectory(targetFilePath);

ftpClient.storeFile(sourceFile.getName(), is);

final int replyCode = ftpClient.getReplyCode();

final String replyMessage = ftpClient.getReplyString();

if (isCommandFailed(replyCode)) {

log.error(String.format(UPLOAD_FILE_REPLY, logPrefix, replyMessage));

throw new IOException("Failed to upload file: " + sourceFilePath);

} else {

log.info(String.format(UPLOAD_FILE_REPLY, logPrefix, replyMessage));

}

}

}

開發者ID:Microsoft,項目名稱:azure-maven-plugins,代碼行數:27,

示例3: upload

​點讚 3

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public boolean upload(String remoteDir, String remoteFileName, File localFile) {

FTPClient ftp = null;

try {

ftp = initFtpClient(remoteDir);

if (ftp == null) {

logger.debug("ftp初始化失敗");

return false;

}

try (InputStream is = new FileInputStream(localFile)) {

boolean storeRet = ftp.storeFile(remoteFileName, is);

if (!storeRet) {

logger.debug("上傳檔案失敗");

return false;

}

}

return true;

} catch (IOException e) {

logger.error("FTP操作異常", e);

return false;

} finally {

close(ftp);

}

}

開發者ID:wyp0596,項目名稱:elegant-springboot,代碼行數:32,

示例4: uploadFileToWebApp

​點讚 2

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public static void uploadFileToWebApp(PublishingProfile profile, String fileName, InputStream file) {

FTPClient ftpClient = new FTPClient();

String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);

String server = ftpUrlSegments[0];

String path = "./site/wwwroot/webapps";

if (fileName.contains("/")) {

int lastslash = fileName.lastIndexOf('/');

path = path + "/" + fileName.substring(0, lastslash);

fileName = fileName.substring(lastslash + 1);

}

try {

ftpClient.connect(server);

ftpClient.login(profile.ftpUsername(), profile.ftpPassword());

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

for (String segment : path.split("/")) {

if (!ftpClient.changeWorkingDirectory(segment)) {

ftpClient.makeDirectory(segment);

ftpClient.changeWorkingDirectory(segment);

}

}

ftpClient.storeFile(fileName, file);

ftpClient.disconnect();

} catch (IOException e) {

e.printStackTrace();

}

}

開發者ID:Azure-Samples,項目名稱:acr-java-manage-azure-container-registry,代碼行數:33,

示例5: uploadFileToFunctionApp

​點讚 2

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public static void uploadFileToFunctionApp(PublishingProfile profile, String fileName, InputStream file) {

FTPClient ftpClient = new FTPClient();

String[] ftpUrlSegments = profile.ftpUrl().split("/", 2);

String server = ftpUrlSegments[0];

String path = "site/wwwroot";

if (fileName.contains("/")) {

int lastslash = fileName.lastIndexOf('/');

path = path + "/" + fileName.substring(0, lastslash);

fileName = fileName.substring(lastslash + 1);

}

try {

ftpClient.connect(server);

ftpClient.login(profile.ftpUsername(), profile.ftpPassword());

ftpClient.setFileType(FTP.ASCII_FILE_TYPE);

for (String segment : path.split("/")) {

if (!ftpClient.changeWorkingDirectory(segment)) {

ftpClient.makeDirectory(segment);

ftpClient.changeWorkingDirectory(segment);

}

}

ftpClient.storeFile(fileName, file);

ftpClient.disconnect();

} catch (IOException e) {

e.printStackTrace();

}

}

開發者ID:Azure-Samples,項目名稱:acr-java-manage-azure-container-registry,代碼行數:33,

示例6: uploadFile

​點讚 2

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public static boolean uploadFile(String url,int port,String username, String password, String path, String filename, InputStream input) {

boolean success = false;

FTPClient ftp = new FTPClient();

try {

int reply;

ftp.connect(url, port);//連接FTP服務器

//如果采用默認端口,可以使用ftp.connect(url)的方式直接連接FTP服務器

ftp.login(username, password);//登錄

reply = ftp.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply)) {

ftp.disconnect();

return success;

}

//設置FTP以2進製傳輸

ftp.setFileType(FTPClient.BINARY_FILE_TYPE);

//TODO 讀取檔案配置判斷是否使用主動

ftp.enterLocalPassiveMode();//被動

//ftp.enterLocalActiveMode();//主動

//創建目錄

mkDir(path,ftp);

//改變目錄

ftp.changeWorkingDirectory(path);

ftp.storeFile(filename, input);

input.close();

ftp.logout();

success = true;

} catch (IOException e) {

e.printStackTrace();

} finally {

if (ftp.isConnected()) {

try {

ftp.disconnect();

} catch (IOException ioe) {

}

}

}

return success;

}

開發者ID:Xvms,項目名稱:xvms,代碼行數:50,

示例7: testRenameCase

​點讚 2

import org.apache.commons.net.ftp.FTPClient; //導入方法依賴的package包/類

public void testRenameCase() throws Exception

{

logger.debug("Start testRenameCase");

FTPClient ftp = connectClient();

String PATH1="testRenameCase";

try

{

int reply = ftp.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply))

{

fail("FTP server refused connection.");

}

boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN);

assertTrue("admin login successful", login);

reply = ftp.cwd("/Alfresco/User*Homes");

assertTrue(FTPReply.isPositiveCompletion(reply));

// Delete the root directory in case it was left over from a previous test run

try

{

ftp.removeDirectory(PATH1);

}

catch (IOException e)

{

// ignore this error

}

// make root directory for this test

boolean success = ftp.makeDirectory(PATH1);

assertTrue("unable to make directory:" + PATH1, success);

ftp.cwd(PATH1);

String FILE1_CONTENT_2="That's how it is says Pooh!";

ftp.storeFile("FileA.txt" , new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8")));

assertTrue("unable to rename", ftp.rename("FileA.txt", "FILEA.TXT"));

}

finally

{

// clean up tree if left over from previous run

ftp.disconnect();

}

}

開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:61,

注:本文中的org.apache.commons.net.ftp.FTPClient.storeFile方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。