public void MoveUp(IFTPConnection connection) { _cwdIsDirty = true; connection.Lock(); connection.SendCommand("CWD " + MOVEUPDIR); connection.Unlock(); }
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); } }
public FTPDataConnection(IFTPConnection conn) { _conn = conn; _transType = conn.TransferType; set_transfer_type(conn, _transType); _conn.Lock(); set_up_data_connection(conn); }
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; }
public string[] Dir(IFTPConnection connection) { //"NLST" string [] fileList; using(var dataConn = new FTPDataConnection(connection)) { fileList = dataConn.GetFileList(); } return fileList; }
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>(); }
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; }
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); }
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; }
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(); } }
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; }
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(); } }
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); }
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(); }
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; }
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; }
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; }
public void Add(IFTPConnection conn, string name) { if (name == "") return; var ftpd = new FTPDirectory(conn, name, parent_url); _list.Add(ftpd); }
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); }
public FTPRepository(IFTPConnection conn, IFTPNavigator nav, IFTPFileService fileSvc, IFTPLocalFileRepository fileRepo) { _conn = conn; _fileRepo = fileRepo; _nav = nav; _fileSvc = fileSvc; Prefix = ""; }
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; }
protected FTPBase(IFTPConnection connection) { _connection = connection; crlf = "\r\n".ToCharArray(); }
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; }
protected FTPDirectory(IFTPConnection connection, string name) : base(connection) { _dir_name = name; }
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()) + "/"; }
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; }
private string[] set_directory(IFTPConnection connection, string remotePath) { _cwdIsDirty = true; var absolutePath = adjustAndReturnCurrentDirectory(remotePath, connection); return connection.SendCommand("CWD " + absolutePath); }
public FTPFile(IFTPConnection conn, string parent) : base(conn,parent) { }
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); } }
public void Add(IFTPConnection conn, string name) { if (name == "") return; _list.Add(name); }
public FTPSite(IFTPConnection conn) : base(conn, "") { }