Re: Retrieve a list of files from a remote server? - WeOnlyDo Discussion board

Re: Retrieve a list of files from a remote server? (General questions)

by Kamal, Thursday, January 13, 2005, 15:21 (7051 days ago) @ wodSupport

I'm trying to download them and remove them from that remote directory!

I've written the following code:

----------------------------------------------------------
public static SortedList fileNames;

private static void sftp_AttributesDataEvent(object Sender, SFTP.AttributesArgs[] Args)
{
for (int i=0;i<Args.Length;i++)
{
//if(Args.Name != . && Args.Name != .. )
{
fileNames.Add(i, Args.Name);
}
}
}

private void ExecuteSFTPMethods()
{
sftp = new SFTP();

sftp.Blocking = true;
sftp.Hostname = this.txtHostname.Text;
sftp.Login = this.txtLogin.Text;
sftp.Password = this.txtPassword.Text;

sftp.Connect();

sftp.LocalPath = this.txtLocalPath.Text.Replace( DateTime , { + DateTime.Now.Day.ToString() + } );
sftp.RemotePath = this.txtRemotePath.Text;

sftp.AttributesDataEvent += new SFTP.AttributesDataDelegate(sftp_AttributesDataEvent);

fileNames = new SortedList();

try
{
sftp.ListAttributes(sftp.RemotePath);

for ( int i = 0; i < fileNames.Count; i++ )
{
sftp.GetFile(sftp.LocalPath, sftp.RemotePath + fileNames.GetByIndex(i));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
sftp.Disconnect();
-------------------------------------------------------------

The directory has 2 files, but the list above (fileNames sortedlist) return 4 files, the first file and the second file are the . and .. and the rest are the correct file names.

In addition, the remotePath gets changed after getting the file (i.e. executing the GetFile() method). why is that?

So in short, i need a safe way to retrieve all the files ONLY, no directories or any other thing..!?

Thank you.


Complete thread: