for ftpfile[] is available but for SftpfFile[] is not available.

0 votes
asked Jul 21, 2011 by karthickgedms (120 points)
edited Jul 21, 2011

I want to list all the files and folders in remote directory on server after connecting to the solaris 10 server.In server FTP functionality is disabled only SFTP is enabled.I need a method which will retrieve file as a file and also folder as a folder type.I am able to connect to the server using sftp and jsch-0.1.44.jar file.

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jul 21, 2011 by Lukas Pokorny (100,710 points)
edited Jul 21, 2011

I'm not sure I completely understand what exactly is the problem here. In Rebex FTP, there is FtpItem object and FtpList object (a collection of FtpItem objects). In Rebex SFTP, there is SftpItem and SftpItemCollection (a collection of SftpItem objects. FtpItem is very similar to SftpItem and FtpList is very similar to SftpItemCollection.

To check whether an item is a file or directory, you can either use IsFile and IsDirectory properties or the Type property. Example:

        Sftp sftp = new Sftp();
        sftp.Connect("server01", 22);
        sftp.Login("tester01", "password");

        SftpItemCollection list = sftp.GetList();
        foreach (SftpItem item in list)
        {
            // display last modification date    
            Console.Write(item.Modified.ToString("u"));

            // display item type (usually a directory or file)
            Console.Write(item.Type.ToString().PadLeft(16, ' '));

            // display item size
            Console.Write(item.Size.ToString().PadLeft(10, ' '));

            // display item name
            Console.Write(" {0}", item.Name);
            Console.WriteLine();
        }
...