임 zip 파일을 만들기위한 DotNetZip를 사용하여 이 업로드에 대한 FTP로 둘 다 완벽하게 작동.
서버와의 연결이 끊어 질 경우 이미 업로드 된 파일이 있는지 ftp 서버를 확인하고 싶습니다. 그런 다음 연결이 다시 설정되면 업로드 프로세스 (시작부터가 아님)를 계속합니다.
주석이있는 코드는 다음과 같습니다.
public void DoResume(string output,string address, string username,string password)
{
// create instance of uploading method
var ftpClient = new ftp(address, username, password);
// get the location of all files in output directory
// output is the location of zip files
var filesAddress = Directory.GetFiles(output);
// get location of all files in output directory
// var filesName = Directory.GetFiles(output).select(Path.GetDileName).ToArray();
// get name of uploaded files
var getuploadedfiles = ftpClient.directoryListSimple("/");
// Upload Files
foreach (var serverfile in getuploadedfiles)
{
foreach (var fadddress in filesAddress)
{
var outputfile = Path.GetFileName(fadddress);
if (serverfile != outputfile)
{
// save *fadddress* file as *outputfile* in server
ftpClient.upload(outputfile, fadddress);
}
}
}
코드가 수행해야하는 작업은 다음과 같습니다. 파일이 이미 업로드되었는지 확인하고, 참이면 다음 파일로 건너 뛰고 다시 확인하고, 업로드되지 않은 경우이 파일에 대해 업로드를 수행합니다.
이것이 일어날 일입니다 : 첫 번째 파일을 제외한 모든 파일을 다시 업로드합니다.
이 코드는 서버를 확인합니다. 이전에 업로드되지 않은 파일이 있으면 계속 업로드합니다.
public void DoResume(string output,string address, string username,string password)
{
var ftpClient = new ftp(address, username, password);
// Get the name of all files in output directory
var localfiles = Directory.GetFiles(output).Select(Path.GetFileName).ToArray();
/* Get names of uploaded files */
var getuploadedfiles = ftpClient.directoryListSimple("/");
// Get files those are not uploaded
var diff = localfiles.Except(getuploadedfiles);
/* Upload Files */
foreach (var dif in diff)
{
foreach (var file in localfiles)
{
if (dif != file) continue;
var filetoupload = $"{output}{dif}";
ftpClient.upload(file, filetoupload);
Console.WriteLine("{0} been uploaded", filetoupload);
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다