Re: Put command from C# results in resumable file upload error
The remote path needed a preceding dot! Knew it was a dumb mistake.
transferResult = session.PutFiles(@"c:\local\*", "./TEST/IN/Load/", false, transferOptions);
Using WinSCP 5.13.4.
I've created a proof of concept C# console app which follows the standard example very closely here:
https://winscp.net/eng/docs/library#example
I've used the windows client and can copy files to remote site ok.
When running my .exe it doesn't copy the files and I get the following error message:
Error deleting file 'Load'. After resumable file upload the existing destination file must be deleted. If you do not have permissions to delete file destination file, you need to disable resumable file transfers.
No such file or directory.
Error code: 2
Error message from server: File not found: /username/TEST/IN/Load
I tried 2 ways of disabling ResumeSupport as per code sample below (one is commented out).
I looked for an .ini file on the server but cannot find it after seeing others been advised to disable ResumeSupport there as well. There is only an .rnd file at AppData/Roaming in my user's profile.
What is confusing is that the File not found is actually a folder name and not a file.
I must be doing something very dumb and hope someone can help.
Thanks
static void Main(string[] args)
{
try
{
TransferResumeSupport resumeSupport = new TransferResumeSupport();
resumeSupport.State = TransferResumeSupportState.Off;
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "the.hostname.com",
PortNumber = 22,
UserName = "username",
Password = "thepassword",
SshHostKeyFingerprint = "ssh-rsa 2048 my key here..."
};
//sessionOptions.AddRawSettings("ResumeSupport", "2");
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
transferOptions.ResumeSupport = resumeSupport;
TransferOperationResult transferResult;
transferResult = session.PutFiles(@"c:\local\*", @"/TEST/IN/Load/", false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
//foreach (TransferEventArgs transfer in transferResult.Transfers)
//{
// Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
//}
}
}
catch (Exception e)
{
Console.WriteLine(String.Format("Error message: {0}", e.Message));
}
}