上傳檔案到sftp伺服器

2021-10-24 18:05:35 字數 960 閱讀 4151

/**

* 上傳檔案到sftp伺服器

** @param remotepath sftp伺服器路徑

* @param filename sftp伺服器檔名

* @param closeflag 是否要關閉本次sftp連線: true-關閉, false-不關閉

* @param filepathflag 是否要建立遠端的指定目錄: true-建立, false-不建立

* @throws ioexception

*/public

boolean

upfile2

(string remotepath, string filename, inputstream input,

boolean closeflag,

boolean filepathflag)

throws exception

this

.channel.cd(

"/")

;for

(int i =

0; i < dirs.length; i++)}

}this

.channel.cd(

"/");}

this

.channel.

cd(remotepath)

;this

.channel.

put(input, filename)

; flag =

true;}

catch

(sftpexception e)

finally

catch

(exception localexception1)

}// 判斷是否要關閉本次sftp連線

if(closeflag)

}return flag;

}

使用SFTP上傳檔案到伺服器的簡單使用

最近用到sftp上傳檔案查詢了一些資料後自己做了一點總結,方便以後的查詢 將檔案上傳到伺服器 param filepath 檔案路徑 param channelsftp channelsftp物件 return public static boolean uploadfile string file...

sftp上傳到遠端伺服器

開發遇到乙個需求,需要將通過sftp上傳到遠端伺服器上,之前沒用過這個功能,折騰了我好幾天才搞定,下面記錄下我的處理方法 sftp ssh2.sftp 連線sftp conn ssh2 connect ip 埠 登入 ssh2 auth password conn,user password res...

AngularJs 上傳檔案到伺服器

define angular angular route angular resource angular animate angular growl angular ngupload controllers index directives index filters index services...