Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.7k views
in .NET FTP by (240 points)
Hi all, which is the most efficient way to download and then move files from one folder to another on an SFTP server using edtFTPnet/PRO ?

I would like to Download all the files in an SFTP folder and move them to another SFTP folder name "old". I must also make sure that I do not pick up any new files from the SFTP that were not downloaded when moving.

At the moment I have the following code:
                    _secureClient.ServerDirectory = "/home/xxxxx";

                    FTPFile[] files = _secureClient.GetFileInfos(_secureClient.ServerDirectory, "*.csv", false);

                    foreach (FTPFile file in files)
                    {
                        _secureClient.DownloadFile(localPath, file.Name);
                        // move from _secureClient.ServerDirectory TO _secureClient.ServerDirectory + "/old"
                    }


1. Is this the most efficient way to do this?
2. How do I move the files? Is it a simple download from one server directory to another?

Thanks

6 Answers

0 votes
by (162k points)
The very first thing to try is to see if you can rename the files, using the path, from one directory to another. Many servers support this, but not necessarily all since it's not explicitly stated in the FTP spec.
0 votes
by (240 points)
yes renaming the files worked fine, and the file was moved from one folder to another.

What if I have thousands of files?

Should I ... Download ALL, then move ALL.... or.... Download and move 1 file at a time?
Which is the more effiecient way?

thanks
0 votes
by (162k points)
I'm a little confused by your reply - you say that renaming the files on the server worked (i.e. you didn't need to download), but then you talk about downloading them if there are 1000s?
0 votes
by (240 points)
sorry maybe i wasnt clear.

I have various files in Folder1 on the SFTP server and need to:
- Download all the files in Folder1
- Once downloading is finished I need to move the original files from Folder1 to Folder2 on the SFTP server

I am moving the files, so that the next time I connect to Folder1 to download the NEW files I would not see ALL files again.

Hope its clearer :)
0 votes
by (162k points)
Oh, I see. I don't think there would be much difference in efficiency.

One possibility though - if they are in a remote folder say abc, the server may allow you to rename the folder to abc_old or whatever you need. That would save moving them individually, although this won't work if you need to do this process repeatedly.
0 votes
by (240 points)
ok great. thanks for your help

Categories

...