Example #1
0
        public void CopyDirectory(string localParentPath, string localDirectoryName,
                                  FtpHelper targetFtpOperation, string targetParentPath, string targetDirectoryName, Action <string, int> CopyAction)
        {
            string localFullPath  = localParentPath + localDirectoryName;
            string targetFullPath = targetParentPath + targetDirectoryName;

            if (CheckHaveDirectory(localFullPath))
            {
                if (targetFtpOperation.CheckHaveDirectory(targetFullPath))
                {
                    targetFtpOperation.DeleteDirectory(targetFullPath);
                }
                targetFtpOperation.CreateDirectory(targetFullPath);
                List <string> fileNames = GetFileList(localFullPath, WebRequestMethods.Ftp.ListDirectory);
                foreach (var fileName in fileNames)
                {
                    CopyFile(localFullPath + "/" + fileName, targetFtpOperation, targetFullPath + "/" + fileName);
                }

                if (CopyAction != null)
                {
                    CopyAction(localDirectoryName, fileNames.Count);
                }
            }
        }
Example #2
0
 public void CopyFile(string localFtpPath, FtpHelper targetFtpOperation, string targetFtpPath)
 {
     if (CheckHaveDirectory(localFtpPath))
     {
         string targetDirectory = GetParentDirectory(targetFtpPath);
         if (!targetFtpOperation.CheckHaveDirectory(targetDirectory))
         {
             targetFtpOperation.CreateDirectory(targetDirectory);
         }
         Stream downloadStream = GetResponseStream(localFtpPath, WebRequestMethods.Ftp.DownloadFile);
         Stream uploadStream   = targetFtpOperation.GetRequestStream(targetFtpPath, WebRequestMethods.Ftp.UploadFile);
         byte[] buff           = new byte[bufferSize];
         int    length;
         while ((length = downloadStream.Read(buff, 0, bufferSize)) != 0)
         {
             uploadStream.Write(buff, 0, length);
             if (length < bufferSize)
             {
                 break;
             }
         }
         downloadStream.Close();
         uploadStream.Close();
     }
 }
Example #3
0
        public void CopyDirectory(string localParentPath, string localDirectoryName, 
            FtpHelper targetFtpOperation, string targetParentPath, string targetDirectoryName,Action<string,int> CopyAction)
        {
            string localFullPath = localParentPath + localDirectoryName;
            string targetFullPath = targetParentPath + targetDirectoryName;
            if (CheckHaveDirectory(localFullPath))
            {
                if (targetFtpOperation.CheckHaveDirectory(targetFullPath))
                {
                    targetFtpOperation.DeleteDirectory(targetFullPath);
                }
                targetFtpOperation.CreateDirectory(targetFullPath);
                List<string> fileNames = GetFileList(localFullPath, WebRequestMethods.Ftp.ListDirectory);
                foreach (var fileName in fileNames)
                {
                    CopyFile(localFullPath + "/" + fileName, targetFtpOperation, targetFullPath + "/" + fileName);
                }

                if (CopyAction != null)
                {
                    CopyAction(localDirectoryName, fileNames.Count);
                }
            }
        }
Example #4
0
 public void CopyFile(string localFtpPath, FtpHelper targetFtpOperation, string targetFtpPath)
 {
     if (CheckHaveDirectory(localFtpPath))
     {
         string targetDirectory = GetParentDirectory(targetFtpPath);
         if (!targetFtpOperation.CheckHaveDirectory(targetDirectory))
         {
             targetFtpOperation.CreateDirectory(targetDirectory);
         }
         Stream downloadStream = GetResponseStream(localFtpPath, WebRequestMethods.Ftp.DownloadFile);
         Stream uploadStream = targetFtpOperation.GetRequestStream(targetFtpPath, WebRequestMethods.Ftp.UploadFile);
         byte[] buff = new byte[bufferSize];
         int length;
         while ((length = downloadStream.Read(buff, 0, bufferSize)) != 0)
         {
             uploadStream.Write(buff, 0, length);
             if (length < bufferSize)
             {
                 break;
             }
         }
         downloadStream.Close();
         uploadStream.Close();
     }
 }