Пример #1
0
 public void MoveUp(IFTPConnection connection)
 {
     _cwdIsDirty = true;
     connection.Lock();
     connection.SendCommand("CWD " + MOVEUPDIR);
     connection.Unlock();
 }
Пример #2
0
        public override void Open(IRFProcessingContext context)
        {
            switch (SiteType)
            {
            case RFFTPSiteType.SFTP:
                if (!string.IsNullOrWhiteSpace(ConnectionKeyPath))
                {
                    if (Password.IsBlank())
                    {
                        _connection = new SFTPConnection(Hostname, Port, Username, ConnectionKeyPath, ConnectionKeyPassword);
                    }
                    else
                    {
                        _connection = new SFTPConnection(Hostname, Port, Username, Password, ConnectionKeyPath, ConnectionKeyPassword);
                    }
                }
                else
                {
                    _connection = new SFTPConnection(Hostname, Port, Username, Password);
                }
                break;

            case RFFTPSiteType.FTP:
                _connection = new FTPConnection(Hostname, Port, Username, Password);
                break;

            default:
                throw new RFSystemException(this, "Unknown FTP site type {0}", SiteType);
            }
        }
Пример #3
0
 public FTPDataConnection(IFTPConnection conn)
 {
     _conn = conn;
     _transType = conn.TransferType;
     set_transfer_type(conn, _transType);
     _conn.Lock();
     set_up_data_connection(conn);
 }
Пример #4
0
 protected FTPBase(IFTPConnection connection, string parent)
 {
     crlf = "\r\n".ToCharArray();
     if (parent.Substring(parent.Length - 1, 1) != "/")
         parent += "/";
     if(parent.IndexOf("ftp://") < 0)
         parent = "ftp://" + parent;
     _connection = connection;
     _base_url = parent;
 }
Пример #5
0
 public string[] Dir(IFTPConnection connection)
 {
     //"NLST"
     string []    fileList;
     using(var dataConn = new FTPDataConnection(connection))
     {
             fileList = dataConn.GetFileList();
     }
     return fileList;
 }
Пример #6
0
 public FTPDirectory(IFTPConnection connection, 
     string name, string parent)
     : base(connection, parent)
 {
     _dir_name = name;
     name += "/";
     _dlist = new FTPDirectoryList(BaseURL.ConcatenateWebPaths(name));
     _flist = new FTPFileList(BaseURL.ConcatenateWebPaths(name));
     _locallist = new List<FileEntity>();
 }
Пример #7
0
        public int DeleteFile(IFTPConnection connection, string remoteFileName)
        {
            connection.Lock();
            int returnValue = 0;
            string[] tempMessageList = connection.SendCommand("DELE " + remoteFileName);

            returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
            connection.Unlock();
            return returnValue;
        }
Пример #8
0
        public void MoveFile(IFTPConnection connection, string remoteFileName, string toRemotePath)
        {
            if (toRemotePath.Length > 0 && toRemotePath.Substring(toRemotePath.Length - 1, 1) != "/")
            {
                toRemotePath = toRemotePath + "/";
            }

            var result = rename_file(connection, remoteFileName, toRemotePath.ConcatenateWebPaths(remoteFileName.GetWebFilename()));
            if (result != 350 && result != 250)
                throw new ApplicationException("Error moving file: " + connection.LastMessage);
        }
Пример #9
0
 private static int rename_file(IFTPConnection connection, string fromRemoteFileName, string toRemoteFileName)
 {
     connection.Lock();
     int returnValue = 0;
     string[] tempMessageList = connection.SendCommand("RNFR " + fromRemoteFileName);
     var currentMsg = tempMessageList.Last();
     returnValue = FTPUtilities.GetMessageReturnValue(currentMsg);
     if (returnValue == 350)
     {
         tempMessageList = connection.SendCommand("RNTO " + toRemoteFileName);
         returnValue = FTPUtilities.GetMessageReturnValue(currentMsg);
     }
     connection.Unlock();
     return returnValue;
 }
Пример #10
0
 public void GetFile(IFTPConnection connection, string localFilePath, string remoteFileName)
 {
     Stream stream = File.Open (localFilePath,FileMode.Create,FileAccess.Write,FileShare.None);
     try
     {
         using (var dataConn = new FTPDataConnection(connection))
         {
             dataConn.GetStream(remoteFileName, stream);
         }
     }
     finally
     {
         stream.Close();
     }
 }
Пример #11
0
        public string GetCurrentDirectory(IFTPConnection connection)
        {
            int i = 0;
            do
            {
                string [] msgs = connection.SendCommand("PWD");
                CurrentDirectory = extract_directory(msgs);
                connection.SetCurrentDirectory(CurrentDirectory);
                i++;
                if (i == 3)
                    throw new ApplicationException("Cannot get current directory!");

            } while (CurrentDirectory == null);
            _cwdIsDirty = false;
            return CurrentDirectory;
        }
Пример #12
0
        public void SendFile(IFTPConnection connection, string localFilePath, string remoteFileName)
        {
            var stream = File.OpenRead(localFilePath);
            try
            {

                using(var dataConn = new FTPDataConnection(connection))
                {
                    dataConn.SendStream(stream, remoteFileName);
                }
            }
            finally
            {
                stream.Close();
            }
        }
Пример #13
0
 public FTPFile(IFTPConnection conn, string line, string parent)
     : base(conn,parent)
 {
     line = line.Trim();
     try
     {
         last_mod = DateTime.Parse(line.Substring(0, 17));
     }
     catch
     {
         if (line.Substring(0, 1) != "-")
         {
             locFileName = line;
             return;
         }
     }
     remFileName = name_from_line(line);
 }
Пример #14
0
        private static void set_data_port(IFTPConnection conn, int portNumber)
        {
            conn.Lock();

            int returnValue = 0;
            int portHigh = portNumber >> 8;
            int portLow = portNumber & 255;

            string[] tempMessageList = conn.SendCommand("PORT "
                                                        + FTPUtilities.GetLocalAddressList()[0].ToString().Replace(".", ",")
                                                        + "," + portHigh.ToString() + "," + portLow);

            returnValue = FTPUtilities.GetMessageReturnValue((string)tempMessageList.Last());
            if (returnValue != 200)
            {
                throw new Exception((string)tempMessageList.Last());
            }
            conn.Lock();
        }
Пример #15
0
 public int SetCurrentDirectory(IFTPConnection connection, string remotePath)
 {
     if(_cwdIsDirty)
         CurrentDirectory = GetCurrentDirectory(connection);
     if (remotePath.SameAsCurrentFTPDirectory(CurrentDirectory) && remotePath != MOVEUPDIR) return 220;
     connection.Lock();
     int returnValue = 0;
     string[] tempMessageList = set_directory(connection, remotePath);
     returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
     connection.Unlock();
     CurrentDirectory = GetCurrentDirectory(connection);
     return returnValue;
 }
Пример #16
0
 private static int set_mode(IFTPConnection conn, string mode)
 {
     conn.Lock();
     int returnValue = 0;
     string[] tempMessageList = conn.SendCommand(mode);
     returnValue = FTPUtilities.GetMessageReturnValue((string)tempMessageList.Last());
     conn.Unlock();
     return returnValue;
 }
Пример #17
0
        private TcpClient create_data_client(IFTPConnection conn)
        {
            int port = get_port_number(conn);

            //IPEndPoint ep = new IPEndPoint(GetLocalAddressList()[0], port);

            var client = new TcpClient();

            //client.Connect(ep);
            try
            {
                client.Connect(conn.Host, port);
            }
            catch (ApplicationException ex)
            {
                _currentMsg = "TcpClient.Connect() failed:  " + ex.Message;
                return null;
            }

            return client;
        }
Пример #18
0
 public void Add(IFTPConnection conn, string name)
 {
     if (name == "") return;
     var ftpd = new FTPDirectory(conn, name, parent_url);
     _list.Add(ftpd);
 }
Пример #19
0
 private int send_stream_within_locked_context(IFTPConnection conn, string remoteFileName, Stream stream)
 {
     if (_client == null)
         return 0;
     string[] tempMessageList = conn.SendCommand("STOR " + remoteFileName);
     string message = tempMessageList[0];
     var returnValue = FTPUtilities.GetMessageReturnValue(message);
     if((returnValue == 150 || returnValue == 125))
     {
         perform_background_upload(conn.Mode,stream);
     }
     else
     {
         return -1;
     }
     tempMessageList = conn.Read();
     message = tempMessageList[0];
     return FTPUtilities.GetMessageReturnValue(message);
 }
Пример #20
0
 public FTPRepository(IFTPConnection conn, IFTPNavigator nav, IFTPFileService fileSvc, IFTPLocalFileRepository fileRepo)
 {
     _conn = conn;
     _fileRepo = fileRepo;
     _nav = nav;
     _fileSvc = fileSvc;
     Prefix = "";
 }
Пример #21
0
        private static TcpListener create_data_listener(IFTPConnection conn)
        {
            int port = get_port_number(conn);
            set_data_port(conn, port);

            IPHostEntry localHost = Dns.GetHostEntry(Dns.GetHostName());
            var listner = new TcpListener(localHost.AddressList[0], port);

            //TcpListener listner = new TcpListener(port);
            return listner;
        }
Пример #22
0
 protected FTPBase(IFTPConnection connection)
 {
     _connection = connection;
     crlf = "\r\n".ToCharArray();
 }
Пример #23
0
 private int set_transfer_type(IFTPConnection conn, FTPFileTransferType type)
 {
     int result = 0;
     switch (type)
     {
         case FTPFileTransferType.ASCII:
             result = set_mode(conn, "TYPE A");
             break;
         case FTPFileTransferType.Binary:
             result = set_mode(conn, "TYPE I");
             break;
         default:
             _currentMsg = "Invalid File Transfer Type";
             break;
     }
     return result;
 }
Пример #24
0
 protected FTPDirectory(IFTPConnection connection, string name)
     : base(connection)
 {
     _dir_name = name;
 }
Пример #25
0
 private string adjustAndReturnCurrentDirectory(string path, IFTPConnection connection)
 {
     var arr = path.Split("/".ToCharArray());
     var lst = new List<string>();
     foreach(string fldr in arr)
     {
         if(fldr != "")
         {
             if(fldr == "..")
                 MoveUp(connection);
             else
             {
                 lst.Add(fldr);
             }
         }
     }
     return string.Join("/", lst.ToArray()) + "/";
 }
Пример #26
0
 private static int get_port_number(IFTPConnection conn)
 {
     int port = 0;
     conn.Lock();
     switch (conn.Mode)
     {
         case FTPMode.Active:
             var rnd = new Random((int)DateTime.Now.Ticks);
             port = DATA_PORT_RANGE_FROM + rnd.Next(DATA_PORT_RANGE_TO - DATA_PORT_RANGE_FROM);
             break;
         case FTPMode.Passive:
             int returnValue = 0;
             string[] tempMessageList = conn.SendCommand("PASV");
             returnValue = FTPUtilities.GetMessageReturnValue(tempMessageList.Last());
             if (returnValue != 227)
             {
                 if (tempMessageList.Last().Length > 4)
                 {
                     throw new Exception(tempMessageList.Last());
                 }
                 throw new Exception(tempMessageList.Last() + " Passive Mode not implemented");
             }
             var message = tempMessageList.Last();
             int index1 = message.IndexOf(",", 0);
             int index2 = message.IndexOf(",", index1 + 1);
             int index3 = message.IndexOf(",", index2 + 1);
             int index4 = message.IndexOf(",", index3 + 1);
             int index5 = message.IndexOf(",", index4 + 1);
             int index6 = message.IndexOf(")", index5 + 1);
             port = 256 * int.Parse(message.Substring(index4 + 1, index5 - index4 - 1)) + int.Parse(message.Substring(index5 + 1, index6 - index5 - 1));
             break;
     }
     conn.Unlock();
     return port;
 }
Пример #27
0
 private string[] set_directory(IFTPConnection connection, string remotePath)
 {
     _cwdIsDirty = true;
     var absolutePath = adjustAndReturnCurrentDirectory(remotePath, connection);
     return connection.SendCommand("CWD " + absolutePath);
 }
Пример #28
0
 public FTPFile(IFTPConnection conn, string parent)
     : base(conn,parent)
 {
 }
Пример #29
0
 private void set_up_data_connection(IFTPConnection conn)
 {
     if (conn.Mode == FTPMode.Active)
     {
         _listener = create_data_listener(conn);
         _listener.Start();
     }
     else
     {
         _client = create_data_client(conn);
     }
 }
Пример #30
0
 public void Add(IFTPConnection conn, string name)
 {
     if (name == "") return;
     _list.Add(name);
 }
Пример #31
0
 public FTPSite(IFTPConnection conn)
     : base(conn, "")
 {
 }