Пример #1
0
		/// <summary>
		/// Get data from the FTP server using the currently
		/// set transfer mode.
		/// </summary>
		/// <param name="localPath">Local file to put data in.</param>
		/// <param name="remoteFile">Name of remote file in current directory.</param>
		public virtual void Get(string localPath, string remoteFile)
        {
            lastFileTransferred = remoteFile;

            if (Directory.Exists(localPath))
            {
                localPath = Path.Combine(localPath, remoteFile);
                log.Debug("Setting local path to " + localPath);
            }

			// events called before get in case event-handlers want to
			// do any FTP operations
			if (TransferStarted != null)
				TransferStarted(this, new EventArgs());
			if (TransferStartedEx != null)
			{
				TransferEventArgs e = new TransferEventArgs(localPath, remoteFile, TransferDirection.DOWNLOAD, transferType);
				TransferStartedEx(this, e);
				localPath = e.LocalFilePath;
			}

			// get according to set type
            try 
            {
                if (transferType == FTPTransferType.ASCII)
                {
                    GetASCII(localPath, remoteFile);
                }
                else
                {
                    GetBinary(localPath, remoteFile);
                }
            }
            catch (SystemException ex)
            {
                ValidateTransferOnError();
                log.Error("SystemException in Get(string,string)", ex);
                throw;
            }
            ValidateTransfer();

			if (TransferComplete != null)
				TransferComplete(this, new EventArgs());
			if (TransferCompleteEx != null)
				TransferCompleteEx(this, new TransferEventArgs(localPath, remoteFile, TransferDirection.DOWNLOAD, transferType));
		}
Пример #2
0
 /// <summary>
 /// Callback from the FTP client. This is called when a file has been downloaded
 /// We're just sending a message to the current window so it can update its view
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void Connection_TransferCompleteEx(object sender, TransferEventArgs e)
 {
   Log.Info("FTPConnection: Transfer completed: {0}->{1}", e.RemoteFilename, e.LocalFilePath);
   try
   {
     FTPClient ftpclient = sender as FTPClient;
     foreach (FtpConnection client in ftpConnections)
     {
       if (client.Connection == ftpclient)
       {
         GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_FILE_DOWNLOADED, 0, 0, 0, 0, 0, null);
         msg.Label = client.OriginalRemoteFileName;
         msg.Label2 = client.LocalFileName;
         GUIGraphicsContext.SendMessage(msg);
         return;
       }
     }
   }
   catch (Exception ex)
   {
     Log.Error(ex);
   }
 }
Пример #3
0
 public virtual void Get(string localPath, string remoteFile)
 {
     if (Directory.Exists(localPath))
     {
         localPath = Path.Combine(localPath, remoteFile);
         this.log.Debug("Setting local path to " + localPath);
     }
     if (this.TransferStarted != null)
     {
         this.TransferStarted(this, new EventArgs());
     }
     if (this.TransferStartedEx != null)
     {
         TransferEventArgs e = new TransferEventArgs(localPath, remoteFile, TransferDirection.DOWNLOAD, this.transferType);
         this.TransferStartedEx(this, e);
         localPath = e.LocalFilePath;
     }
     try
     {
         if (this.transferType == FTPTransferType.ASCII)
         {
             this.GetASCII(localPath, remoteFile);
         }
         else
         {
             this.GetBinary(localPath, remoteFile);
         }
     }
     catch (SystemException exception)
     {
         this.ValidateTransferOnError();
         this.log.Error("SystemException in Get(string,string)", exception);
         throw;
     }
     this.ValidateTransfer();
     if (this.TransferComplete != null)
     {
         this.TransferComplete(this, new EventArgs());
     }
     if (this.TransferCompleteEx != null)
     {
         this.TransferCompleteEx(this, new TransferEventArgs(localPath, remoteFile, TransferDirection.DOWNLOAD, this.transferType));
     }
 }
Пример #4
0
 private void Connection_TransferStartedEx(object sender, TransferEventArgs e)
 {
   Log.Debug("ftp: Transfer started {0}->{1}", e.RemoteFilename, e.LocalFilePath);
 }