Downloading a file using WinSCP.NET/COM with temporary file names

I am creating a small .NET application in C # to upload files to an FTP server. I am using the .NET DLL for WinSCP to do this, and I have been trying to find a good solution to my problem.

The FTP folder in which all my files will be placed will be monitored by another application. Then this application will accept these files and process them automatically.

So what I want to avoid is that my files are captured by the application until the transfer is complete.

So, I want to use a temporary use of the file name, or perhaps a temporary folder, and then move the files when the download is complete.

What do you suggest as the best approach? And the second question is that in WinSCP.NET there should be an option Transfer Resume, which transfers the file with a temporary name and renames it upon completion. But I can't get this to work and am looking for any clues on how to get this to work?

+5
source share
1 answer

You are correct that the "transfer to temporary file name" function in WinSCP looks like a path.

It makes a WinSCP boot file with the name added to it .filepart, removing the extension as soon as it is done.

TransferOptions transferOptions = new TransferOptions();
transferOptions.ResumeSupport.State = TransferResumeSupportState.On;
session.PutFiles(@"d:\toupload\myfile.dat", "/home/user/", false, transferOptions).Check();

Although only supported by SFTP.


With FTP, you must do this manually.

session.PutFiles(@"d:\toupload\myfile.dat", "/home/user/myfile.dat.filepart").Check();
session.MoveFile("/home/user/myfile.dat.filepart", "/home/user/myfile.dat");

, , Session.PutFiles TransferOperationResult, Session.MoveFile .

TransferOperationResult transferResult;
transferResult = session.PutFiles(@"d:\toupload\*.dat", "/home/user/*.filepart")

// Throw on any error
transferResult.Check();

// Rename uploaded files
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
    string finalName = transfer.Destination.Replace(".filepart", ".dat");
    session.MoveFile(transfer.Destination, finalName);
}

PowerShell / .


. SFTP ( FTP) .

+4

All Articles