1

EDIT: Found the issue. I was not typing the entire folder structure when trying to save the file. The problem is now solved.

I'm trying to upload a file using c# and chilkat to a customer, but i keep getting an error code.

I work for a logistics company, and we have many types of integration with our customers. We use c# and chilkat for a while, and it works with every other customer we have. This is a new customer but i made tests using FileZilla, and everything works (create, delete, download, upload), the credentials are the same. Our Chilkat license is updated (today) and we have the latest version. I have tested with other customers, the same code, and it works (more than 10 other customers)

string username = "login";
string password = "pass";

Chilkat.SFtp sftp = new Chilkat.SFtp();
bool success = sftp.UnlockComponent("Hello World");
if (success != true)
    throw new Exception("Invalid License");

sftp.ConnectTimeoutMs = 5000;
sftp.IdleTimeoutMs = 10000;
success = sftp.Connect("address", 22);
if (success != true)
    throw new Exception("Host could not be reached. Invalid Host.");
success = sftp.AuthenticatePw(username, password);
if (success != true)
    throw new Exception("Invalid Credentials.");

success = sftp.InitializeSftp();
if (success != true)
    throw new Exception("Connection could not be initialized.");

string[] fileList = Directory.GetFiles(@"c:\files\");
foreach (string item in fileList)
{
    string handle = sftp.OpenFile("IN/" + Path.GetFileName(item), "writeOnly", "createTruncate");
    if (handle == null)
    {
        string lastErrorText = sftp.LastErrorText;
        //throw new Exception("Could not create a handle for the desired file");
    }
    else
    {
        success = sftp.UploadFile(handle, item);
        if (success != true)
            throw new Exception("Could not Upload the File");
        else
            Console.WriteLine("File {0} uploaded", item);

        success = sftp.CloseHandle(handle);
        if (success != true)
            throw new Exception("Could not close the handle");
        else
            File.Delete(item);
    }
}

I expected the file to be uploaded, but it fails. The "LastErrorText" Variable comes back with the following text:

ChilkatLog:
  OpenFile:
    DllDate: Mar 18 2019
    ChilkatVersion: 9.5.0.77
    UnlockPrefix: Start my 30-day Trial
    Architecture: Little Endian; 32-bit
    Language: .NET 4.6 / x86 / VS2017
    VerboseLogging: 0
    SshVersion: SSH-2.0-SSHD-CORE-1.7.0
    SftpVersion: 3
    sftpOpenFile:
      remotePath: IN/214KCF_S903211745.txt
      access: writeOnly
      createDisposition: createTruncate
      v3Flags: 0x1a
      Sent FXP_OPEN
      StatusResponseFromServer:
        Request: FXP_OPEN
        InformationReceivedFromServer:
          StatusCode: 3
          StatusMessage: operation not permitted
        --InformationReceivedFromServer
      --StatusResponseFromServer
    --sftpOpenFile
    Failed.
  --OpenFile
--ChilkatLog
  • Are all the customers on the same server? If not, is the server in fact using sftp and not ftp -- chilkat might not play nice if that is the case. Also, it looks like you can turn on verboseLogging per the error message. – DavidTheDev Apr 15 '19 at 18:18
  • Hey. Not all customers are in the same server, no. – Raphael FMacedo Apr 15 '19 at 18:29

0 Answers0