使用ftp上傳檔案

2022-05-12 06:38:42 字數 1354 閱讀 8155

當初做這個的緣由是甲方要求使用者上傳的檔案單獨存放在另一台伺服器上即檔案伺服器與專案所在伺服器分離。

commons-net

commons-net

3.6

工具類:檔案伺服器在阿里雲,注意主動模式和被動模式配置

public

static

boolean storeftpfile(string now,listfilelist,string storepath,string url,int port,string username,string password) throws

filenotfoundexception

//判斷ftp目錄是否存在,如果不存在則建立目錄,包括建立多級目錄

ftp.enterlocalactivemode();

//判斷ftp目錄是否存在,如果不存在則建立目錄,包括建立多級目錄

string s = "/"+storepath;

string dirs = s.split("/");

ftp.changeworkingdirectory("/");

//按順序檢查目錄是否存在,不存在則建立目錄

for(int i=1; dirs!=null&&i)

}else

} }

//設定檔案操作目錄

ftp.changeworkingdirectory(storepath);

//設定檔案操作目錄

ftp.changeworkingdirectory(storepath);

//設定檔案型別,二進位制

ftp.setfiletype(ftpclient.binary_file_type);

//設定緩衝區大小

ftp.setbuffersize(3072);

//上傳檔案

for(file file:filelist)

//關閉輸入流

fis.close();

//登出伺服器

ftp.logout();

} catch

(ioexception e)

//判斷連線是否存在

if(ftp.isconnected())

} catch

(ioexception e2)

e.printstacktrace();

} finally

//判斷連線是否存在

if(ftp.isconnected())

} catch

(ioexception e)

}return

result;

}

使用bat上傳FTP檔案

echo off rem 2017 04 10 rem by geln rem 演示ftp命令列上傳單個檔案,沒有設定ftp的上傳目錄 rem 上傳成功返回0,上傳失敗返回1 rem 設定變數 外部呼叫 ftp up上傳檔案.bat 主機ip 使用者名稱 密碼 當前計算機上傳目錄 上傳檔名 if n...

java使用ftp上傳檔案

linux伺服器配置 安裝ftp yum install vsftpd 啟動服務 service vsftpd start 開機啟動 chkconfig level 35 vsftpd on 設定許可權 vi etc vsftpd vsftpd.conf 將配置檔案中 anonymous enabl...

FTP檔案上傳

是網上找的例子,原文找不到了。public class ftputils2 return 判斷是否登入成功 public boolean ftplogin else ftp伺服器連線回答 int reply this.ftpclient.getreplycode if ftpreply.isposi...