Inheritance: FtpFileEventArgs
示例#1
0
        public static void Cmd_APPE(Object sender, CommandEventArgs e)
        {
            FtpSession lSession = (FtpSession)e.Session;

            if (lSession.State == FtpState.LoggedIn)
            {
                if ((e.AllParameters.Length == 0) || (!ValidFilename(e.AllParameters)))
                {
                    e.Connection.WriteLine("501 Syntax error in parameters or arguments.");
                    return;
                }

                String lNewDir = e.AllParameters;
                if (lNewDir.StartsWith("/"))
                {
                    lNewDir = ValidateDirectory(lNewDir);
                }
                else
                {
                    String lTemp = lSession.Directory;
                    if (!lTemp.EndsWith("/"))
                        lTemp = lTemp + "/";
                    lNewDir = ValidateDirectory(lTemp + lNewDir);
                }

                FtpTransferEventArgs lArgs = new FtpTransferEventArgs(e.Session, e.Connection, e.Server);
                lArgs.FileName = lNewDir;
                lArgs.Append = true;
                lArgs.RestartPoint = 0;
                lSession.RestartPoint = 0;

                try
                {
                    ((FtpServer)lArgs.Server).InvokeOnCanStoreFile(lArgs);
                }
                catch (FtpException ex)
                {
                    lArgs.Connection.WriteLine(ex.ToString());
                    return;
                }
                catch
                {
                    lArgs.Connection.WriteLine("500 Internal Error");
                    return;
                }

                if (lArgs.Ok)
                {
                    if (lSession.Passive)
                        e.Connection.WriteLine("125 Data connection already open; transfer starting");

                    if (!ValidateConnection(lSession))
                    {
                        e.Connection.WriteLine("425 Unable to build data connection");
                        return;
                    }
                    if (!lSession.Passive)
                        e.Connection.WriteLine("150 Opening data connection");
                }
                else
                {
                    lArgs.Connection.WriteLine("550 Permission Denied");
                    return;
                }
                lSession.State = FtpState.Transfer;

                if (lSession.TransferThread != null)
                {
                    lSession.TransferThread.Abort();
                    lSession.TransferThread = null;
                }
                lSession.TransferThread = new FtpTransferThread(lArgs, true);
            }
            else
            {
                e.Connection.WriteLine("503 Bad sequence of commands.");
            }
        }
示例#2
0
 internal protected virtual void InvokeOnCanRetrieveFile(FtpTransferEventArgs e)
 {
     if (this.OnCanRetrieveFile != null)
         this.OnCanRetrieveFile(this, e);
 }
示例#3
0
        public FtpTransferThread(FtpTransferEventArgs e, Boolean store)
        {
            this.fEventArgs = e;
            this.fStore = store;

            new Thread(new ThreadStart(Execute)).Start();
        }
		protected override void InvokeOnRetrieveFile(FtpTransferEventArgs ea)
		{
			VirtualFtpSession lSession = (VirtualFtpSession)ea.Session;
			IFtpFolder lFolder;
			string lFilename;

			lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession);
			IFtpFile lFile = lFolder.GetFile(lFilename, lSession);
			lFile.GetFile(ea.DataChannel);
			ea.Ok = true;
		}
		protected override void InvokeOnCanRetrieveFile(FtpTransferEventArgs ea)
		{
			VirtualFtpSession lSession = (VirtualFtpSession)ea.Session;
			IFtpFolder lFolder;
			string lFilename;

			lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession);
			IFtpFile lFile = lFolder.GetFile(lFilename, lSession);
			ea.Ok = (lFile != null && lFile.AllowRead(lSession));
		}
		protected override void InvokeOnCanStoreFile(FtpTransferEventArgs ea)
		{
			VirtualFtpSession lSession = (VirtualFtpSession)ea.Session;
			IFtpFolder lFolder;
			string lFilename;

			lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession);
			ea.Ok = lFolder.AllowPut(lSession);
		}