2024年2月20日发(作者:)

83 public void Put(string localPath, string remotePath) 84 { 85 try 86 { 87 using (var file = ad(localPath)) 88 { 89 Connect(); 90 File(file, remotePath); 91 Disconnect(); 92 } 93 } 94 catch (Exception ex) 95 { 96 throw new Exception($"SFTP Upload File fail,Error Message:{e}"); 97 } 98 } 99

100 #endregion101

102 #region SFTP Batch Upload File103

104 ///

105 /// SFTP Batch Upload File106 /// 107 /// Local file path(without file name)108 /// Remote file path(without file name)109 public void BatchPut(string localPath, string remotePath)110 {111 string uploadFullName = "";112 string remoteFullName = "";113 try114 {115 Connect();116 DirectoryInfo fdir = new DirectoryInfo(localPath);117 FileInfo[] file = es();118

119 if ( != 0)120 {121 foreach (FileInfo f in file) //show all files under the path122 {123 using (var upLoadFile = ad(me))124 {125 uploadFullName = me;126 remoteFullName = remotePath + "/" + ;127

128 File(upLoadFile, remotePath + "/" + );129 }130 }131 }132 }133 catch (Exception ex)134 {135 throw new Exception($"SFTP Batch Upload File Fail,Error Message:{e}");136 }137 }138

139 #endregion SFTP Batch Upload File140

141 #region SFTP Get File142

143 ///

144 /// SFTP Get File145 /// 146 /// Remote file path147 /// Local file path148 public void Get(string remotePath, string localPath)149 {150 try151 {152 Connect();153 var byt = lBytes(remotePath);154 Disconnect();155 llBytes(localPath, byt);156 }157 catch (Exception ex)158 {159 throw new Exception($"SFTP Get File Fail,Error Message:{ e }");160 }161 }162

163 #endregion164

165 #region Delete SFTP File166

167 ///

168 /// Delete SFTP File169 /// 170 /// Remote File path171 public void Delete(string remoteFile)172 {173 try174 {175 Connect();176 (remoteFile);177 Disconnect();178 }179 catch (Exception ex)180 {181 throw new Exception($"Remote File Path Fail,Error Message:{ e }");182 }183 }184

185 #endregion186

187 #region Get SFTP File List188

189 ///

190 /// Get SFTP File List191 ///

192 /// Local path193 /// file suffix194 /// 195 public ArrayList GetFileList(string remotePath, string fileSuffix)196 {197 try198 {199 Connect();200 var files = rectory(remotePath);201 Disconnect();202 var objList = new ArrayList();203 foreach (var file in files)204 {205 string name = ;206 if ( > ( + 1) && fileSuffix == ing( - ))207 {208 (name);209 }210 }211 return objList;212 }213 catch (Exception ex)214 {215 throw new Exception($"Get SFTP File List Fail,Error Message:{e}");216 }217 }218

219 #endregion220

221 #region Move SFTP File222

223 ///

224 /// Move SFTP File225 /// 226 /// Old Remote Path227 /// New Remote Path228 public void Move(string oldRemotePath, string newRemotePath)229 {230 try231 {232 Connect();233 File(oldRemotePath, newRemotePath);234 Disconnect();235 }236 catch (Exception ex)237 {238 throw new Exception($"Move SFTP File Faile,Error Message:{e}");239 }240 }241

242 #endregion243

244 protected virtual void Dispose(bool disposing)245 {246 if (!disposing) return;247 // dispose managed resources248 e();249 // free native resources250 }251

252 public void Dispose()253 {254 Dispose(true);255 ssFinalize(this);256 }257 }View Code